2.0.0releasedJust In Time (JIT) Image Manipulation

Image thumbnailer

Clone URLhttps://github.com/symphonycms/jit_image_manipulation.git

Add as a submodulegit submodule add https://github.com/symphonycms/jit_image_manipulation.git extensions/jit_image_manipulation --recursive

Compatibility

2.x.x2.1.x2.2.x2.3.x2.4.x2.5.x2.6.x2.7.02.7.12.7.22.7.32.7.42.7.52.7.62.7.72.7.82.7.92.7.10
No1.141.141.161.311.312.0.02.0.02.0.02.0.02.0.02.0.02.0.02.0.02.0.02.0.02.0.02.0.0

Readme

JIT Image Manipulation

A simple way to manipulate images "just in time" via the URL. Supports caching, image quality settings and loading of offsite images.


NOTE: Version 2.x is not working properly, please use the 1.x branch until further notice!


Installation

Information about installing and updating extensions can be found in the Symphony documentation.

Updating

1.17

This release raises the minimum requirement to Apache 2.2+.

1.15

Since version 1.15, JIT configuration has moved from /manifest/ to the /workspace/ folder. This change will automatically happen when you update the extension from the "System > Extensions" page.

Due to some .htaccess changes in Symphony 2.0.6+, it is recommended that you edit your core Symphony .htaccess to remove anything before 'extensions/' in the JIT rewrite. It should look like the following regardless of where you installed Symphony:

### IMAGE RULES
RewriteRule ^image/(.+.(jpg|gif|jpeg|png|bmp))$ extensions/jit_image_manipulation/lib/image.php?param=$1 [L,NC]

It is not absolutely necessary to do this, but may prevent problems with future releases.

Usage

Basics

The image manipulation is controlled via the URL, eg.:

<img src="{$root}/image/2/80/80/5/fff{image/@path}/{image/filename}" />

The extension accepts four numeric settings and one text setting for the manipulation.

  1. mode
  2. width
  3. height
  4. reference position (for cropping only)
  5. background color (for cropping only)

There are four possible modes:

  • 0 none
  • 1 resize
  • 2 resize and crop (used in the example)
  • 3 crop
  • 4 resize to fit

If you're using mode 2 or 3 for image cropping you need to specify the reference position:

+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 4 | 5 | 6 |
+---+---+---+
| 7 | 8 | 9 |
+---+---+---+

If you're using mode 2 or 3 for image cropping, there is an optional fifth parameter for background color. This can accept shorthand or full hex colors.

  • For .jpg images, it is advised to use this if the crop size is larger than the original, otherwise the extra canvas will be black.
  • For transparent .png or .gif images, supplying the background color will fill the image. This is why the setting is optional

The extra fifth parameter makes the URL look like this:

<img src="{$root}/image/2/80/80/5/fff{image/@path}/{image/filename}" />
  • If you wish to crop and maintain the aspect ratio of an image but only have one fixed dimension (that is, width or height), simply set the other dimension to 0

External sources & Trusted Sites

In order pull images from external sources, you must set up a white-list of trusted sites. To do this, go to "System > Preferences" and add rules to the "JIT Image Manipulation" rules textarea. To match anything use a single asterisk (*).

The URL then requires a sixth parameter, external, (where the fourth and fifth parameter may be optional), which is simply 1 or 0. By default, this parameter is 0, which means the image is located on the same domain as JIT. Setting it to 1 will allow JIT to process external images provided they are on the Trusted Sites list.

<img src="{$root}/image/1/80/80/1/{full/path/to/image}" />
                                ^ External parameter

Recipes

Recipes are named rules for the JIT settings which help improve security and are more convenient. They can be edited on the preferences page in the JIT section and are saved in /workspace/jit-image-manipulation/recipes.php. A recipe URL might look like:

<img src="{$root}/image/thumbnail{image/@path}/{image/filename}" />

When JIT parses a URL like this, it will check the recipes file for a recipe with a handle of thumbnail and apply it's rules. You can completely disable dynamic JIT rules and choose to use recipes only which will prevent a malicious user from hammering your server with large or multiple JIT requests.

Recipes can be copied between installations and changes will be reflected by every image using this recipe.

Version history

Symphony 2.6.0 to 2.x.x

  • JIT image process is it's own Symphony renderer now
  • PSR2 Compliance (for the most part)
  • Do not try to change .htaccess file if it does not exits
  • Extracted the .htaccess procedure into its own class
  • Lots of bug fixes and perf improvements
  • Switch to semver (but should be backward compatible for Apache users)

Symphony 2.6.0 to 2.x.x

  • Add CORS header support (@tmslnz)
  • Added 'max-age' hidden configuration

Symphony 2.6.0 to 2.6.x

  • Fix when no bytes are written but everything worked (#116)

Requires Symphony 2.6.0

  • Fix bad merge and tagging error (#112)

Requires Symphony 2.6.0

  • #110 Fix JIT error with regex recipes

Requires Symphony 2.6.0

  • #103 Fix autoloader issue with Symphony CMS 2.6.0
  • #101 Remove duplicate CACHING declaration
  • #100 Reject invalid image size of 0 x 0
  • #47 Allow CMYK images to be handled

Requires Symphony 2.6.0

  • Mark compatibility with Symphnoy 2.6+

Symphony 2.4 to 2.5.x

  • Mark compatibility with Symphony 2.4+

Requires Symphony 2.4

  • Remove ob_clean as it was unnecessary (@DavidOliver)
  • Add no-transform header to prevent ISP's from compression images (@nitriques)
  • Simplify TMP directory logic (@brendo)
  • Fix whitespace errors (@nilshoerrmann)

Requires Symphony 2.3.2

  • Simplification of .htaccess rule (@michael-e)
  • Fix for unused $recipes variable (@dtan)
  • Fix for caching when using sockets instead of curl (@dustywilson)
  • Update README with updated path (@nitriques)
  • Update Russian and German translations (@alexbirukov and @nilshoerrmann)
  • Update Duplicators to Symphony 2.3 API (@nilshoerrmann)

Requires Symphony 2.3.2

  • Allow all recipes to be deleted from the Preferences page

Requires Symphony 2.3.2

  • Update links to getsymphony.com

Requires Symphony 2.3.2

  • Set GD to ignore invalid JPEG's
  • Match recipes names more specifically, using thumbs and thumb is now possible
  • When saving the .htaccess changes, use the PHP_EOL constant for more consistent output
  • Cache Gateway requests for improved performance
  • Fix potential warnings when checking for trusted sites

Requires Symphony 2.3.2

  • Allow JIT to function with image filenames that have special characters
  • Use Gateway instead of curl directly for HTTP Requests
  • Use the Page class in order to generate HTTP Status codes
  • Adding an option to disable upscaling images
  • Update trusted sites to support subdomains *.ytimg.com etc.

Requires Symphony 2.3

  • Add a Recipes data source
  • Update German translation
  • Fix issue with Apache outputting corrupted images in some situations
  • JIT now follows redirects on external URL's

Requires Symphony 2.3

  • Add recipes
  • Moved settings into /workspace
  • Improve compatibility with servers other than Apache

Symphony 2.0.5 to 2.2.x

  • More robust detection of a temp directory
  • More robust installation

Symphony 2.0.5 to 2.2.x

  • Add a new mode, Resize to Fit, that will conditionally resize your image if it is above the desired width/height otherwise it will leave the image as it. (thanks @21studios)
  • Output the correct file path in 404 errors (thanks @michael-e)
  • Fixes error in the error message when connecting to an external site
  • No longer serves 304 headers when CACHING is disabled in the configuration

Symphony 2.0.5 to 2.2.x

  • Fixes issue where cached images would be delivered even though the original file was removed (thanks @michael-e)
  • Fixes direct display mode (thanks @michael-e)
  • Output errors and correctly set 404 headers when things go wrong

Symphony 2.0.5 to 2.2.x

  • Allow external images to be cached (thanks @michael-e)
  • Fixes PNG and GIF transparency issues (thanks to @designermonkey)
  • Background color on crop becomes optional

Symphony 2.0.5 to 2.2.x

  • Compatibility with Symphony 2.2

Symphony 2.0.2 to 2.0.6

  • Updated to work with 2.0.2 config changes

Symphony 2.0.5 to 2.1.x

  • Sending ETag header with response
  • Added support for HTTP_IF_MODIFIED_SINCE and HTTP_IF_NONE_MATCH request headers, which will mean a 304 Not Modified header can be set (Thanks to Nick Dunn for helping on this one)
  • Added Portuguese and Italian translations (Thanks to @rainerborene & @eKoeS for those)

Symphony 2.0.5 to 2.1.x

  • Added French localisation
  • Adjusted German localisation
  • Fixed a Symphony 2.0.7RC2 compatibility issue.

Symphony 2.0.5 to 2.0.6

  • Added localisation files for Dutch, German, Portuguese (Brazil) and Russian
  • trusted() will look for the jit-trusted-sites before attempting to return its contents. This prevents warnings from showing up in the logs.

Symphony 2.0.2 to 2.0.6

  • Code responsible for .htaccess update will no longer try to append the rewrite base to for path to extensions folder

Symphony 2.0.2 to 2.0.6

  • Fixed bug introduced by usage of the imageAntiAlias() function
  • Errors and warnings are logged in the main Symphony log
  • A dump of internal params are logged in addition to any errors

Symphony 2.0.2 to 2.0.6

  • Adding support for alpha masked images.

Symphony 2.0.2 to 2.0.6

  • Minor changes to how `DOCROOT`` is determined

Symphony 2.0.2 to 2.0.6

  • Disabling extension will remove rule from .htaccess