Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rethink image manipulations with Glide (ForumPHP 2015)
Search
Jonathan Reinink
November 24, 2015
Technology
0
520
Rethink image manipulations with Glide (ForumPHP 2015)
Jonathan Reinink
November 24, 2015
Tweet
Share
More Decks by Jonathan Reinink
See All by Jonathan Reinink
The formula to awesome docs (phpDay 2017)
reinink
0
120
How to open source a PHP package (phpDay 2017)
reinink
1
100
The formula to awesome docs (Lone Star PHP 2016)
reinink
0
830
The PHP Package Checklist (Lone Star PHP 2016)
reinink
0
250
Framework agnostic packages for the win (SkiPHP 2016)
reinink
1
220
Framework agnostic packages for the win (ForumPHP 2015)
reinink
8
940
Rethink image manipulations with Glide
reinink
3
420
Enough about Classes, Let's Talk Templates
reinink
8
3.6k
Practical deployments for average projects
reinink
4
390
Other Decks in Technology
See All in Technology
カオナビの利用実績をアウトカムへつなげる旅 / example-of-data-management-startup-in-kaonavi
kaonavi
0
120
プロデザ! BY リクルート vol.18_リクルートのリサーチ実践組織「リサーチブーストコミュニティ」
recruitengineers
PRO
3
240
Reducing Cross-Zone Egress at Spotify with Custom gRPC Load Balancing Recap
koh_naga
0
130
"好き"との生活/Regularly update profile with GitHub Actions
judeeeee
0
150
普段有償でサポート業務をしているCSAが技術知見を無料で公開する理由
07jp27
1
640
WebアプリケーションにおけるPDOの使い方入門 / phpcon odawara 2024
meihei3
2
430
開発生産性向上サービスを作るFindyが自分たちで開発生産性を爆上げした組織づくりの歩み / Findy's path to boosting its own development productivity 2024-04-17
ma3tk
3
340
テストプロセスで大事にしていること #jasstnano
makky_tyuyan
0
130
o11y入門_外形監視を利用したWebアプリケーションへの最適なモニタリング_TechBrew
k5k
3
100
20240416_devopsdaystokyo
kzkmaeda
1
190
Aurora MySQL v3(MySQL8.0互換)の オンラインDDLの罠挙動を全バージョンで検証した
yutakikai
1
150
「ふりかえりのふりかえり」をふりかえり、実のあるふりかえりにする
naitosatoshi
0
220
Featured
See All Featured
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
76
41k
Adopting Sorbet at Scale
ufuk
67
8.6k
How GitHub Uses GitHub to Build GitHub
holman
468
290k
KATA
mclloyd
14
12k
Infographics Made Easy
chrislema
237
18k
Mobile First: as difficult as doing things right
swwweet
216
8.6k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
186
16k
Robots, Beer and Maslow
schacon
PRO
155
7.9k
Why You Should Never Use an ORM
jnunemaker
PRO
50
8.6k
In The Pink: A Labor of Love
frogandcode
138
21k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
Automating Front-end Workflow
addyosmani
1355
200k
Transcript
None
Jonathan Reinink Software developer from Canada. Been writing PHP for
over 15 years. Marketing agency for over a decade. Started contract development this year. I <3 open source.
A native PHP template system
Warning: This talk describes some Glide 1.0 features, which hasn’t
been released yet.
What is Glide? A wonderfully easy on-demand image manipulation library
written in PHP.
Glide Intervention Image Library GD (PHP) ImageMagick
Glide has an HTTP based API. Manipulate images using GET
parameters.
/img/kayaks.jpg
/img/kayaks.jpg?w=800
/img/kayaks.jpg?w=800&h=500
/img/kayaks.jpg?w=600&h=600&fit=crop
/img/kayaks.jpg?w=600&h=600&fit=crop-left
/img/kayaks.jpg?border=10,5000,overlay
kayaks.jpg?mark=billabong.png&markw=30w&markpad=3w&markpos=top-right
/img/kayaks.jpg?blur=10
/img/kayaks.jpg?filt=sepia
/img/kayaks.jpg?fm=gif /img/kayaks.jpg?fm=png /img/kayaks.jpg?fm=jpg /img/kayaks.jpg?fm=pjpg Encoding. /img/kayaks.jpg?fm=jpg&q=90
So where did this idea come from? Anyone remember TimThumb?
None
None
Only save your original images, not the manipulations. Then request
different image sizes when they are needed.
Use GD or ImageMagick. Glide is built on the Intervention
Image library.
use League\Glide\ServerFactory; ! $server = ServerFactory::create([ 'driver' => 'imagick', ]);
Use any file storage. Glide uses the Flysystem file system
abstraction library.
Use Glide in an app, or create a separate image
server. Offload image manipulations to a separate server on larger projects
Basic Glide installation. Using out-of-the-box settings.
Route::get('/img/users/{id}', function ($id) { ! $server = ServerFactory::create([ 'source' =>
'path/to/source', 'cache' => 'path/to/cache', ]); ! $server->outputImage('users/'.$id.'.jpg', [ 'w' => 300, 'h' => 400 ]); });
Route::get('/img/{path}', function ($path) { ! $server = ServerFactory::create([ 'source' =>
'path/to/source', 'cache' => 'path/to/cache', ]); ! $server->outputImage($path, $_GET); });
Route::get('/img/{path}', function ($path) { ! $server = ServerFactory::create([ 'source' =>
'path/to/source', 'cache' => 'path/to/cache', ]); ! return $server->getImageResponse($path, $_GET); });
Route::get('/img/{path}', function (Glide $server, Request $request, $path) { return $server->getImageResponse($path,
$request->all()); });
HTTP responses. Glide supports a wide range of response types,
including PSR-7 and HttpFoundation.
use League\Glide\Responses\SymfonyResponseFactory; ! $server = ServerFactory::create([ 'response' => SymfonyResponseFactory() ]);
Setup Glide using S3. Free your images from the local
disk.
$server = ServerFactory::create([ 'source' => 'path/to/source', 'cache' => 'path/to/cache', ]);
$source = new Local('path/to/source'); $cache = new Local('path/to/cache'); ! $server
= ServerFactory::create([ 'source' => new Filesystem($source), 'cache' => new Filesystem($cache), ]);
$client = S3Client::factory([ 'key' => 'your-key', 'secret' => 'your-secret', ]);
! $s3 = new AwsS3Adapter($client, 'your-bucket'); $cache = new Local('path/to/cache'); ! $server = ServerFactory::create([ 'source' => new Filesystem($s3), 'cache' => new Filesystem($cache), ]);
Defaults & presets. Automatically set the default encoding or add
a standard watermark.
$server = ServerFactory::create([ 'defaults' => [ 'mark' => 'logo.png', 'markw'
=> '30w', 'markpad' => '5w', ] ]);
$server = ServerFactory::create([ 'presets' => [ 'small' = [ 'w'
=> 200, 'h' => 200, 'fit' => 'crop', ], ] ]);
<img src="kayaks.jpg?p=small">
<img src="kayaks.jpg?p=small,watermarked">
<img src="kayaks.jpg?p=small,watermarked&filt=sepia">
Set a max image size. Prevent accidental resizing of massive
images.
$server = ServerFactory::create([ 'max_image_size' => 2000*2000, ]);
Prevent URL hacking by signing the image URLs. An important
security step that should always be used in production.
// Create a URL builder $builder = UrlBuilderFactory::create( 'http://example.com', 'your-sign-key'
); ! // Generate a URL $url = $builder->getUrl('cat.jpg', ['w' => 500]); ! // Use the URL in your app echo '<img src="'.$url.'">';
<img src="http://example.com/img/cat.jpg? w=500&token=af3dc18fc6bfb2afb521e587c348b904">
use League\Glide\Signatures\SignatureFactory; use League\Glide\Signatures\SignatureException; ! try { // Validate HTTP
signature SignatureFactory::create('your-sign-key') ->validateRequest($path, $_GET); } catch (SignatureException $e) { // Handle error }
Disabling cache. Let another service, like Varnish, do the work.
$source = new Local('path/to/source'); $cache = new MemoryAdapter(); ! $server
= ServerFactory::create([ 'source' => new Filesystem($source), 'cache' => new Filesystem($cache), ]);
Preprocess images. Helpful on heavy traffic websites.
// Handle your image upload $image = ... ! //
Dispatch the job to your queue $this->dispatch( new ProcessImageManipulations($image) ) ! // Run the job foreach (['small', 'medium', 'large'] as $size) { $glide->makeImage($image['path'], ['p' => 'small']); }
Thanks! Follow me on Twitter at @reinink. Rate this talk
https://joind.in/15274.