Posts tagged with image manipulation

A medialibrary package for Laravel 5

by Freek Van der Herten – 3 minute read

At Spatie all our greenfield projects are powered by custom built CMS based on Laravel 5. An important part of the CMS is the medialibrary-component. It handles how uploaded files are associated with models. My intern and I recently took the time to release our medialibrary as a package on GitHub.…

Read more

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.

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);

Read more

Join thousands of developers

Every two weeks, I share practical tips, tutorials, and behind-the-scenes insights from maintaining 300+ open source packages.

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

HTTP based image manipulations

Glide is a wonderfully easy on-demand image manipulation library written in PHP. It’s straightforward API is exposed via HTTP, similar to cloud image processing services like Imgix and Cloudinary. Glide leverages powerful libraries like Intervention Image (for image handling and manipulation) and Flysystem (for file system abstraction).
http://glide.thephpleague.com/

It comes with the ability to secure image URL's using a private signing key. I'm a bit worried about flooding the server but the owner of the package states that

... the cache filesystem + caching in league/flystem (with Redis/Memcache) should (at least this is the case in my testing) result in a speedy response...
There's also a risk that over time your cache will become gigantic. The maintainers of the package are already discussing possible solutions.

Read more