Image Presets
Image presets are defined in config/enso/media.php in the presets array.
Height and width
A simple preset is to define the height and width of the output image. For example, the following code would produce an image 1920px wide and 600px tall.
'presets' => [
'hero' => [1920, 600],
],
Crop Style
You can provide a third parameter to control what kind of cropping is performed.
'presets' => [
'hero' => [1920, 600, 'no-upscale'],
],
cover(default) - The image will be cropped towards the centre (or the focal point if one is set) to create an image that is exactly the size requested.contain- The whole image will be visible. If necessary, white bars will be added to the top and bottom/left and right. This colour can be overridden when calling$image->getResizeUrl().no-upscale- This will create an image in the same way as cover with the restriction that neither dimension will be bigger than the original image size. Because of this the resulting image may not be the same size as requested dimensions.no-upscale-forced-aspect- This works the same as no-upscale but if the image is smaller than the requested size then a solid background colour will be used to fill in the empty space.
Basic Filters
You can provide two more parameters to lighten or darken the generated image. This is useful for generating images that will have text layerd on top of them.
'presets' => [
'hero' => [1920, 600, 'cover', 'darken', .5]
],
lighten- Will apply a white layer over the top of the image with an opacity of the given amount (0-1).darken- Will apply a black layer over the top of the image with an opacity of the given amount (0-1).
A Note About Caching
You can apply filters to existing presets, however I would not recommend it as the old image may be cached in Cloudflare, browsers and maybe elsewhere. If you create a new preset it will have a new URL and will therefore not be incorrectly cached.
If you do create a new preset, consider deleting the images that were made for the old preset. Think of the disk space!