Transforming images on the fly
What you as an end-user of an Imbo installation will be doing most of the time, is working with images. This is what Imbo was originally made for, and this chapter includes details about all the different image transformations Imbo supports.
All image transformations can be triggered by specifying the t query parameter. This parameter must be used as an array so that you can provide several image transformations. The transformations will be applied to the image in the same order as they appear in the URL. Each element in this array represents a single transformation with optional parameters, specified as a string. If the t query parameter is not an array or if any of its elements are not strings, Imbo will respond with HTTP 400.
Below you will find all image transformations supported “out of the box”, along with their parameters. Some transformations are rarely used with HTTP GET, but are instead used by event listeners that transform images when they are added to Imbo (HTTP POST). If this is the case it will be mentioned in the description of the transformation.
Auto rotate image based on EXIF data - t[]=autoRotate
This transformation will auto rotate the image based on EXIF data stored in the image. This transformation is rarely used per request, but is typically used by the Auto rotate image event listener when adding images to Imbo.
Examples:
t[]=autoRotate
Blur the image - t[]=blur
This transformation can be used to blur the image.
Parameters:
modeThe blur type (optional). Defaults to
gaussian. Possible values are:gaussianWhen adding gaussian blur, the
radiusandsigmaparameters are required.adaptiveWhen adding adaptive blur, the
radiusandsigmaparameters are required. Adaptive blur decrease the blur in the part of the picture near to the edge of the image canvas.motionWhen adding motion blur, the
radius,sigmaandangleparameters are required.radialWhen adding radial blur, the
angleparameter is required.
radiusThe radius of the Gaussian, in pixels, not counting the center pixel.
sigmaThe standard deviation of the Gaussian, in pixels.
angleThe number of degrees to rotate the image.
Examples:
t[]=blur:radius=1,sigma=2t[]=blur:type=adaptive,radius=2,sigma=4
Add an image border - t[]=border
This transformation will apply a border around the image.
Parameters:
colorColor of the border in hexadecimal. Defaults to
000000(You can also specify short values likef00(ff0000)).widthWidth of the border in pixels on the left and right sides of the image. Defaults to
1.heightHeight of the border in pixels on the top and bottom sides of the image. Defaults to
1.modeMode of the border. Can be
inlineoroutbound. Defaults tooutbound. Outbound places the border outside of the image, increasing the dimensions of the image.inlinepaints the border inside of the image, retaining the original width and height of the image.
Examples:
t[]=bordert[]=border:mode=inlinet[]=border:color=000t[]=border:color=f00,width=2,height=2
Expand the image canvas - t[]=canvas
This transformation can be used to change the canvas of the original image.
Parameters:
widthWidth of the surrounding canvas in pixels. If omitted the width of
<image>will be used.heightHeight of the surrounding canvas in pixels. If omitted the height of
<image>will be used.modeThe placement mode of the original image.
free,center,center-xandcenter-yare available values. Defaults tofree.xX coordinate of the placement of the upper left corner of the existing image. Only used for modes:
freeandcenter-y.yY coordinate of the placement of the upper left corner of the existing image. Only used for modes:
freeandcenter-x.bgBackground color of the canvas. Defaults to
ffffff(also supports short values likef00(ff0000)).
Examples:
t[]=canvas:width=200,mode=centert[]=canvas:width=200,height=200,x=10,y=10,bg=000t[]=canvas:width=200,height=200,x=10,mode=center-yt[]=canvas:width=200,height=200,y=10,mode=center-x
Clip the image - t[]=clip
TODO: Write me!
Compress the image - t[]=compress
This transformation compresses images on the fly resulting in a smaller payload. It is advisable to only use this transformation in combination with an image type in the URL (for instance .jpg or .png). This transformation is not applied to images of type image/gif.
Parameters:
levelThe level of the compression applied to the image. The effect this parameter has on the image depends on the type of the image. If the image in the response is an
image/jpega highlevelmeans high quality, usually resulting in larger files. If the image in the response is animage/pnga highlevelmeans high compression, usually resulting in smaller files. If you do not specify an image type in the URL the result of this transformation is not deterministic as clients have different preferences with regards to the type of images they want to receive (via theAcceptrequest header).
Examples:
t[]=compress:level=40
Change image contrast - t[]=contrast
This transformation can be used to change the contrast of the colors in the image.
Parameters:
alphaUsed to adjust the intensity differences between the lighter and darker elements of the image. Can also be negative. Note: this parameter was named
sharpenin Imbo 1.x.betaWhere the midpoint of the gradient will be. This value should be in the range 0 to 1. Default:
0.5.
Examples:
t[]=contrast:alpha=3
Note
If you are getting different results than expected when using negative alpha values, your imagick extension is probably built against an old version of ImageMagick.
Convert the image type - .jpg/.gif/.png
This transformation can be used to change the image type. It is not applied like the other transformations, but is triggered when specifying a custom extension to the <image>. Currently Imbo can convert to:
image/jpegimage/pngimage/gif
Examples:
curl http://imbo/users/<user>/images/<image>.gifcurl http://imbo/users/<user>/images/<image>.jpgcurl http://imbo/users/<user>/images/<image>.png
Crop the image - t[]=crop
This transformation is used to crop the image.
Parameters:
xThe X coordinate of the cropped region’s top left corner.
yThe Y coordinate of the cropped region’s top left corner.
widthThe width of the crop in pixels.
heightThe height of the crop in pixels.
modeThe crop mode (optional). Possible values are:
centerWhen using the center mode the
xandyparameters are ignored, and the center of the cropped area is placed in the center of the original image.center-xCenter the crop on the x-axis. Use the
yparameter to control the upper edge of the crop.center-yCenter the crop on the y-axis. Use the
xparameter to control the left edge of the crop.
Examples:
t[]=crop:x=10,y=25,width=250,height=150t[]=crop:width=100,height=100,mode=centert[]=crop:width=50,height=50,mode=center-x,y=15t[]=crop:width=50,height=50,mode=center-y,x=15
Make a gray scaled image - t[]=desaturate
This transformation desaturates the image (in practice, gray scales it).
Examples:
t[]=desaturate
Draw points of interest - t[]=drawPois
This transformation will draw an outline around all the POIs (points of interest) stored in the metadata for the image. The format of the metadata is documented under the smartSize transformation.
Parameters:
colorColor of the border in hexadecimal format. Defaults to
ff0000(You can also specify short values likef0f(ff00ff)).borderSizeWidth of the border in pixels. Defaults to
2.pointSizeThe diameter (in pixels) of the circle drawn around points of interest that do not have a height and width specified. Defaults to
30.
Examples:
t[]=drawPoist[]=drawPois:borderSize=10t[]=drawPois:color=0f0t[]=drawPois:color=00f,borderSize=10,pointSize=100
Note
This transformation has a bug/limitation: all coordinates are based on the original image. In other words, applying this at the end of a transformation chain which resizes/crops/rotates the image can lead to unexpected results. This will hopefully change in the future.
Make a mirror image - t[]=flipHorizontally
This transformation flips the image horizontally.
Examples:
t[]=flipHorizontally
Flip the image upside down - t[]=flipVertically
This transformation flips the image vertically.
Examples:
t[]=flipVertically
Adjust RGB/CMYK levels in an image - t[]=level
TODO: Write me!
Generate a histogram of the image - t[]=histogram
This transformation will convert the image into a histogram of the image itself, with a size of 256x158 pixels. The size of the generated image can be overridden by using one or more of the supported parameters.
Parameters:
scaleThe amount to scale the histogram. Defaults to
1.ratioThe ratio to use when calculating the height of the image. Defaults to
1.618.redThe color to use when drawing the graph for the red channel. Defaults to
#D93333.greenThe color to use when drawing the graph for the green channel. Defaults to
#58C458.blueThe color to use when drawing the graph for the blue channel. Defaults to
#3767BF.
Examples:
t[]=histogramt[]=histogram:scale=2t[]=histogram:red=f00,green=0f0,blue=00f
Apply an ICC color profile - t[]=icc
Adds an ICC color profile to the image, enforcing the given profile for the next steps in the processing chain until output or another icc transformation is applied.
This transformation requires explicit configuration and is not enabled by default, since you have to register the color profiles you want to make available and their aliases.
To enable the transformation add it in your local configuration file:
<?php
return [
// ...
'transformations' => [
'icc' => function () {
return new Imbo\Image\Transformation\Icc([
'default' => '/path/to/sRGB_v4_ICC_preference.icc',
'srgb' => '/path/to/sRGB_v4_ICC_preference.icc',
]);
},
],
// ...
];
The profile given under the key default will be applied if no specific profile is requested (i.e. if icc is added without a name argument.)
The most common ICC profiles can be downloaded directly from the ICC’s page for sRGB profiles, or from Adobe and their ICC profiles download page.
Parameters:
profileThe name of the profile to apply as defined in the configuration file when adding the transformation.
Examples:
t[]=icct[]=icc:profile=srgb
Adjust levels of the image - t[]=level
This transformation will adjust the levels of an image. You are able to specify individual channels to adjust - by default it will apply to all channels.
Parameters:
channelThe channel to adjust.
r(red),g(green),b(blue),c(cyan),m(magenta),y(yellow),k(black) andall(all channels) are available values. These channels can also be combined, if multiple channels should be adjusted. Defaults toall.amountThe amount to adjust by. Range is from
-100to100. Defaults to1.
Examples:
t[]=levelt[]=level:channel=r,amount=30t[]=level:channel=rg,amount=-45
Enforce a max size of an image - t[]=maxSize
This transformation will resize the image using the original aspect ratio. Two parameters are supported and at least one of them must be supplied to apply the transformation.
Note the difference from the resize transformation: given both width and height, the resulting image will not be the same width and height as specified unless the aspect ratio is the same.
Parameters:
widthThe max width of the resulting image in pixels. If not specified the width will be calculated using the same aspect ratio as the original image.
heightThe max height of the resulting image in pixels. If not specified the height will be calculated using the same aspect ratio as the original image.
Examples:
t[]=maxSize:width=100t[]=maxSize:height=100t[]=maxSize:width=100,height=50
Modulate the image - t[]=modulate
This transformation can be used to control the brightness, saturation and hue of the image.
Parameters:
bBrightness of the image in percent. Defaults to 100.
sSaturation of the image in percent. Defaults to 100.
hHue percentage. Defaults to 100.
Examples:
t[]=modulate:b=150t[]=modulate:b=120,s=130,h=90
Make a progressive image - t[]=progressive
This transformation makes the image progressive.
Examples:
t[]=progressive
Resize the image - t[]=resize
This transformation will resize the image. Two parameters are supported and at least one of them must be supplied to apply the transformation.
Parameters:
widthThe width of the resulting image in pixels. If not specified the width will be calculated using the same aspect ratio as the original image.
heightThe height of the resulting image in pixels. If not specified the height will be calculated using the same aspect ratio as the original image.
Examples:
t[]=resize:width=100t[]=resize:height=100t[]=resize:width=100,height=50
Rotate the image - t[]=rotate
This transformation will rotate the image clock-wise.
Parameters:
angleThe number of degrees to rotate the image (clock-wise).
bgBackground color in hexadecimal. Defaults to
000000(also supports short values likef00(ff0000)).
Examples:
t[]=rotate:angle=90t[]=rotate:angle=45,bg=fff
Apply a sepia color tone - t[]=sepia
This transformation will apply a sepia color tone transformation to the image.
Parameters:
thresholdThreshold ranges from 0 to QuantumRange and is a measure of the extent of the sepia toning. Defaults to
80
Examples:
t[]=sepiat[]=sepia:threshold=70
Smart size the image - t[]=smartSize
This transformation is used to crop the image based on a point of interest (POI) provided either as a transformation parameter or from the image metadata.
Metadata format
The smart size transformation supports reading the POI from the metadata of the image. The POI information is expected to be stored on the poi property in metadata. Below is an example of a valid metadata object containing a 600,240 POI:
{
"poi": [
{
x: 600,
y: 240
}
]
}
Note
The smart size transformation currently takes only the first object into account when cropping the image, but the POIs is stored as an array of objects in order to be easy to expand with more information for a more sophisticated smart size algorithm in the future.
Parameters:
widthThe width of the crop in pixels.
heightThe height of the crop in pixels.
poiThe POI coordinate
x,yto crop around. The parameter is optional if the POI exists in metadata.cropThe closeness of the crop (optional). Possible values are:
closemediumwidefull
Examples:
t[]=smartSize:width=250,height=250,poi=300,200t[]=smartSize:width=250,height=250,poi=300,200,crop=close
Strip image properties and comments - t[]=strip
This transformation removes all properties and comments from the image. If you want to strip EXIF tags from the image for instance, this transformation will do that for you.
Examples:
t[]=strip
Create a thumbnail of the image - t[]=thumbnail
This transformation creates a thumbnail of <image>.
Parameters:
widthWidth of the thumbnail in pixels. Defaults to
50.heightHeight of the thumbnail in pixels. Defaults to
50.fitFit style. Possible values are:
insetoroutbound. Default tooutbound.
Examples:
t[]=thumbnailt[]=thumbnail:width=20,height=20,fit=inset
Create a vertical mirror image - t[]=transpose
This transformation transposes the image.
Examples:
t[]=transpose
Create a horizontal mirror image - t[]=transverse
This transformation transverses the image.
Examples:
t[]=transverse
Add a vignette to the image - t[]=vignette
This transformation can be used to add a vignette to the image.
Parameters:
innerColor at the center of the image, in hexadecimal. Defaults to
none, which means transparent. (You can also specify short values likef00(ff0000)).outerColor at the edge of the image, in hexadecimal. Defaults to
000.scaleScale factor of the vignette.
2will create a vignette twice the size of the original image. Defaults to1.5.
Examples:
t[]=vignettet[]=vignette:outer=ccct[]=vignette:scale=1,outer=333
Add a watermark to the image - t[]=watermark
This transformation can be used to apply a watermark on top of the original image.
Parameters:
imgImage identifier of the image to apply as watermark. Can be set to a default value in configuration by using
<setDefaultImage>.widthWidth of the watermark image in pixels. If omitted the width of
<img>will be used.heightHeight of the watermark image in pixels. If omitted the height of
<img>will be used.positionThe placement of the watermark image.
top-left,top-right,bottom-left,bottom-right,bottom,top,left,rightandcenterare available values. Defaults totop-left.xNumber of pixels in the X-axis the watermark image should be offset from the original position (defined by the
positionparameter). Supports negative numbers. Defaults to0yNumber of pixels in the Y-axis the watermark image should be offset from the original position (defined by the
positionparameter). Supports negative numbers. Defaults to0opacityCan be an integer between 0 and 100 where 0 is fully transparent, and 100 is fully opaque. Defaults to
100
Examples:
t[]=watermark:img=f5f7851c40e2b76a01af9482f67bbf3ft[]=watermark:img=f5f7851c40e2b76a01af9482f67bbf3f,width=200,x=5t[]=watermark:img=f5f7851c40e2b76a01af9482f67bbf3f,height=50,x=-5,y=-5,position=bottom-right,opacity=50
If you want to set the default watermark image you will have to do so in the configuration:
<?php
return [
// ...
'eventListeners' => [
'watermark' => function() {
$transformation = new Imbo\Image\Transformation\Watermark();
$transformation->setDefaultImage('some image identifier');
return $transformation;
},
],
// ...
];
When you have specified a default watermark image you are not required to use the img option for the transformation, but if you do so it will override the default one.