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 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 - If the original image is big enough, this will result in the same as cover, of not it will create a larger image with white around it where necessary. Again, this colour can be overridden as above.

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!