Oh Dear is the all-in-one monitoring tool for your entire website. We monitor uptime, SSL certificates, broken links, scheduled tasks and more. You'll get a notifications for us when something's wrong. All that paired with a developer friendly API and kick-ass documentation. O, and you'll also be able to create a public status page under a minute. Start monitoring using our free trial now.

Generate image manipulations in a Laravel project

Link –

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.

Installation

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.

Usage

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=&quot;{{ GlideImage::setImagePath('kayaks.jpg')->setConversionParameters(['w'=> 50, 'filt'=>'greyscale']) }}&quot; />

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:


GlideImage::setImagePath('kayaks.jpg')
    ->setConversionParameters(['w'=> 50, 'filt'=>'greyscale'])
    ->save($fileWhereImageManipulationMustBeSaved);
Share Post LinkedIn

I write about Laravel, PHP, AI and building better software.

Every two weeks, I share practical tips, tutorials, and behind-the-scenes insights from maintaining 300+ open source packages. Join thousands of developers who read along.

No spam. Unsubscribe anytime. You can also follow me on X.

Found something interesting to share?

The community section is a place where developers share links to articles, tutorials and videos. Submit a link and help fellow developers discover great content. As a thank you, you'll receive a coupon for a discount on Spatie products.