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:gaussian- When adding gaussian blur, the
radiusandsigmaparameters are required. adaptive- When 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. motion- When adding motion blur, the
radius,sigmaandangleparameters are required. radial- When adding radial blur, the
angleparameter is required.
radius- The radius of the Gaussian, in pixels, not counting the center pixel.
sigma- The standard deviation of the Gaussian, in pixels.
angle- The 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:
color- Color of the border in hexadecimal. Defaults to
000000(You can also specify short values likef00(ff0000)). width- Width of the border in pixels on the left and right sides of the image. Defaults to
1. height- Height of the border in pixels on the top and bottom sides of the image. Defaults to
1. mode- Mode 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:
width- Width of the surrounding canvas in pixels. If omitted the width of
<image>will be used. height- Height of the surrounding canvas in pixels. If omitted the height of
<image>will be used. mode- The placement mode of the original image.
free,center,center-xandcenter-yare available values. Defaults tofree. x- X coordinate of the placement of the upper left corner of the existing image. Only used for modes:
freeandcenter-y. y- Y coordinate of the placement of the upper left corner of the existing image. Only used for modes:
freeandcenter-x. bg- Background 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
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:
level- The 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:
alpha- Used 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. beta- Where 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:
x- The X coordinate of the cropped region’s top left corner.
y- The Y coordinate of the cropped region’s top left corner.
width- The width of the crop in pixels.
height- The height of the crop in pixels.
modeThe crop mode (optional). Possible values are:
center- When 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-x- Center the crop on the x-axis. Use the
yparameter to control the upper edge of the crop. center-y- Center 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:
color- Color of the border in hexadecimal format. Defaults to
ff0000(You can also specify short values likef0f(ff00ff)). borderSize- Width of the border in pixels. Defaults to
2. pointSize- The 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
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:
scale- The amount to scale the histogram. Defaults to
1. ratio- The ratio to use when calculating the height of the image. Defaults to
1.618. red- The color to use when drawing the graph for the red channel. Defaults to
#D93333. green- The color to use when drawing the graph for the green channel. Defaults to
#58C458. blue- The 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
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:
channel- The 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. amount- The 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:
width- The 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.
height- The 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:
b- Brightness of the image in percent. Defaults to 100.
s- Saturation of the image in percent. Defaults to 100.
h- Hue 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:
width- The width of the resulting image in pixels. If not specified the width will be calculated using the same aspect ratio as the original image.
height- The 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:
angle- The number of degrees to rotate the image (clock-wise).
bg- Background 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:
threshold- Threshold 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
Sharpen the image - t[]=sharpen¶
This transformation can be used to change the sharpness in the image.
Parameters:
radius- The radius of the Gaussian operator in pixels. Defaults to
2. sigma- The standard deviation of the Gaussian, in pixels. Defaults to
1. gain- The percentage of the difference between the original and the blur image that is added back into the original. Defaults to
1. threshold- The threshold in pixels needed to apply the difference gain. Defaults to
0.05. presetDifferent presets that can be used. The presets are:
light(radius = 2, sigma = 1, gain = 1, threshold = 0.05)moderate(radius = 2, sigma = 1, gain = 2, threshold = 0.05)strong(radius = 2, sigma = 1, gain = 3, threshold = 0.025)extreme(radius = 2, sigma = 1, gain = 4, threshold = 0)
When using any of the presets the different parameters can be overridden by specifying radius, sigma, gain and/or threshold. Not specifying any parameters at all is the same as using the light preset.
Examples:
t[]=sharpent[]=sharpen:preset=light(same as above)t[]=sharpen:preset=extreme,gain=10(use theextremepreset, but use a gain value of 10 instead of 4)t[]=sharpen:radius=2,sigma=1,gain=1,threshold= 0.05(same as usingt[]=sharpen:preset=light, or simplyt[]=sharpen)
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:
width- The width of the crop in pixels.
height- The height of the crop in pixels.
poi- The 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:
closemediumwide
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:
width- Width of the thumbnail in pixels. Defaults to
50. height- Height of the thumbnail in pixels. Defaults to
50. fit- Fit 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:
inner- Color at the center of the image, in hexadecimal. Defaults to
none, which means transparent. (You can also specify short values likef00(ff0000)). outer- Color at the edge of the image, in hexadecimal. Defaults to
000. scale- Scale 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:
img- Image identifier of the image to apply as watermark. Can be set to a default value in configuration by using
<setDefaultImage>. width- Width of the watermark image in pixels. If omitted the width of
<img>will be used. height- Height of the watermark image in pixels. If omitted the height of
<img>will be used. position- The placement of the watermark image.
top-left,top-right,bottom-left,bottom-rightandcenterare available values. Defaults totop-left. x- Number of pixels in the X-axis the watermark image should be offset from the original position (defined by the
positionparameter). Supports negative numbers. Defaults to0 y- Number of pixels in the Y-axis the watermark image should be offset from the original position (defined by the
positionparameter). Supports negative numbers. Defaults to0 opacity- Can 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.