Readme

SilverStripe Optimised Image

This module provides two image manipulation services that can be configured independently:

Run command-line image optimisation tools on images resampled by SilverStripe: reduces the file size of the generated images without reducing fidelity in a noticeable way

Resize images on upload to fit within configured dimensions: prevents images with massive dimensions entering the assets and becoming a memory problem when resampling.

For a SilverStripe 2.4 version check the 0.1 branch.

Configurations for some common image optimisation tools (eg. jpegoptim and optipng) are provided as part of this module, though any command line program can be used with the image optimisation service. No optimisation program binaries are bundled with this module, so you'll need to install any programs you want to use on the target system.

Installation (with composer)

Usage

Resampling Images on upload

By default, resampling on upload is not enabled. To activate it, the ResampleImage extension needs to be added to Image. In your mysite/_config/config.yml add:

yml
Image:
extensions:
- ResampleImage

The default maximum width & height for uploaded images is 1024 x 1024 pixels. Images larger than this will be scaled to fit their largest dimension to this size.

You can set your own maximum height and width for uploaded images by overriding the default config in your mysite/_config/config.yml:

yml
ResampleImage:
max_x: 2000
max_y: 2500

Note that resampling on upload is a destructive process: the original uploaded image is discarded.

Optimising SilverStripe Resampled Images - Selecting a backend

The image backend that SilverStripe uses needs to be changed to either OptimisedGDBackend or OptimisedImagickBackend depending on whether
you want to us GD or Imagick. To do this, in your mysite/_config/config.yml add:

```yml
Image:
backend: OptimisedGDBackend

// or

Image:
backend: OptimisedImagickBackend
```

Configuration options:

enabledCommands

availableCommands

binDirectory

optimisingQuality

At the very least enabledCommands needs to be overridden in your own config in order to enable the optimising of images resampled by SilverStripe.

This can be done as follows,

Create a file mysite/_config/optimisedimage.yml

Add the following contents

```yml

After: 'silverstripe-optimisedimage/config#core'

ImageOptimiserService:
enabledCommands:
- jpegoptim
- optipng
```

If you want to add your own commands, you can override availableCommands e.g.