Image Transformer

Codacy Badge StyleCI License Total Downloads Latest Stable Version

Image transformer dependency for Laravel Enso.


Under the Hood

  • for the non essential libraries, handles missing libraries gracefully, logging the fact but does not throw an error


In order for the optimization to work, you need to have the following packages installed:

  • pngquant
  • gifsicle
  • jpegoptim
  • php7.1-gd or php-imagick

On Linux, you can do that with: sudo apt-get install pngquant gifsicle jpegoptim php7.1-gd


The underlying image processing libraries may use a lot of memory, especially if the processed files are large (for example, for an 8MB file, more than 128MB of memory might be used ), so make sure to configure php accordingly and/or do ini_set(‘memory_limit’, ‘256M’);

Failure to do so may result in silent errors if allotted memory is insufficient.


The ImageTransformer class has 2 public methods:

  • optimize, takes no argument and tries to optimize the file
  • resize, takes the target width and height and resizes the file, possibly changing the aspect ration
  • width, resizes the file to the given width, maintaining aspect ratio
  • height, resizes the file to the given height, maintaining aspect ratio

Note, an ImageTransformerException is thrown if:

  • the gd or imagick extensions are missing
  • a file type not supported for an uploaded file
  • an uploaded file fails the basic validation


The Laravel Enso Core package comes with this package included.