Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer. You can expect quick tips, links to interesting tutorials, opinions and packages. Want to learn the cool stuff? Then sign up now!

Generate image manipulations in a Laravel project

Earlier this month Glide joined The League of Extraordinary Packages. This package provides an easy way to generate image manipulations on the fly. Within a couple of hours I had integrated this wonderful package into both my company’s legacy and current CMS.

The current CMS is based on Laravel. The Glide-integration is now  available as a package on github: freekmurze/laravel-glide.


Nothing too fancy, you’ll have to:

  • use composer to pull in the package
  • install a service provider
  • install a facade
  • publish a config file

Read the specifics on Github.


Assuming you’ve got an image named kayaks.jpg in app/storage/images (this directory can be customized in the config file) you can use this code in a blade view:

<img src="{{ GlideImage::setImagePath('kayaks.jpg')->setConversionParameters(['w'=> 50, 'filt'=>'greyscale']) }}" />

The function will output an URL to a greyscale version of kayaks.jpg that has a width of 50 pixels. As soon as the URL gets hit by your browser, the image will be generated on the fly. The generated image will be saved in app/storage/glide-cache (= the cache directory specified in the input file).

The generated URL will also be signed to prevent jerks from generating unwanted manipulations.

The setConversionParameters-function accepts an array with conversion options. You can take a look at the image API of Glide to see which options are available.

It’s also possible to generate an image directly on the server:

->setConversionParameters(['w'=> 50, 'filt'=>'greyscale'])
Freek Van der Herten is a partner and developer at Spatie, an Antwerp based company that specializes in creating web apps with Laravel. After hours he writes about modern PHP and Laravel on this blog. When not coding he’s probably rehearsing with his kraut rock band.
  • Lloople

    This is a great package, and I want to use it in my projects, but I’m stuck right now. I want to be able to manage with GlideImage all images I have inside public/uploads folder, that contains subfolders like public/uploads/pages, public/uploads/entries, etc… and I don’t know how to configure and use GlideImage for that case. Can you give me some advice please? Thank you for your work