league/glide
Glide is an on-demand PHP image manipulation library served over HTTP. Resize, crop, and apply effects with simple URL parameters, with automatic caching and far-future headers. Works with GD, Imagick, or libvips and Flysystem storage.
In certain situations you may want to define default image manipulations. For example, maybe you want to specify that all images are outputted as JPEGs (fm=jpg). Or maybe you have a watermark that you want added to all images. Glide makes this possible using default manipulations.
<?php
// Set using factory
$server = League\Glide\ServerFactory::create([
'defaults' => [
'mark' => 'logo.png',
'markw' => '30w',
'markpad' => '5w',
]
]);
// Set using setter method
$server->setDefaults([
'mark' => 'logo.png',
'markw' => '30w',
'markpad' => '5w',
]);
Glide also makes it possible to define groups of defaults, known as presets. This is helpful if you have standard image manipulations that you use throughout your app.
<?php
// Set using factory
$server = League\Glide\ServerFactory::create([
'presets' => [
'small' => [
'w' => 200,
'h' => 200,
'fit' => 'crop',
],
'medium' => [
'w' => 600,
'h' => 400,
'fit' => 'crop',
]
]
]);
// Set using setter method
$server->setPresets([
'small' => [
'w' => 200,
'h' => 200,
'fit' => 'crop',
],
'medium' => [
'w' => 600,
'h' => 400,
'fit' => 'crop',
]
]);
To use a presets, set it using the p parameter:
<img src="kayaks.jpg?p=small">
It's also possible to use multiple presets together:
<img src="kayaks.jpg?p=small,watermarked">
It's even possible to use presets with additional parameters:
<img src="kayaks.jpg?p=small,watermarked&filt=sepia">
You can override the default and preset manipulations for a specific request by passing a new parameter (e.x. mark=different.png), or even disable it entirely by setting it to blank (e.x. mark=).
How can I help you explore Laravel packages today?