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
Search
Jonathan Reinink
May 21, 2015
Technology
3
500
Rethink image manipulations with Glide
Jonathan Reinink
May 21, 2015
Tweet
Share
More Decks by Jonathan Reinink
See All by Jonathan Reinink
The formula to awesome docs (phpDay 2017)
reinink
0
150
How to open source a PHP package (phpDay 2017)
reinink
1
120
The formula to awesome docs (Lone Star PHP 2016)
reinink
0
930
The PHP Package Checklist (Lone Star PHP 2016)
reinink
0
270
Framework agnostic packages for the win (SkiPHP 2016)
reinink
1
270
Framework agnostic packages for the win (ForumPHP 2015)
reinink
8
1k
Rethink image manipulations with Glide (ForumPHP 2015)
reinink
0
610
Enough about Classes, Let's Talk Templates
reinink
8
3.7k
Practical deployments for average projects
reinink
4
400
Other Decks in Technology
See All in Technology
Amazon Kendra GenAI Index 登場でどう変わる? 評価から学ぶ最適なRAG構成
naoki_0531
0
120
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
270
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
130
Opcodeを読んでいたら何故かphp-srcを読んでいた話
murashotaro
0
280
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
210
サーバーなしでWordPress運用、できますよ。
sogaoh
PRO
0
110
私なりのAIのご紹介 [2024年版]
qt_luigi
1
120
サイバー攻撃を想定したセキュリティガイドライン 策定とASM及びCNAPPの活用方法
syoshie
3
1.3k
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
360
KubeCon NA 2024 Recap / Running WebAssembly (Wasm) Workloads Side-by-Side with Container Workloads
z63d
1
250
非機能品質を作り込むための実践アーキテクチャ
knih
5
1.5k
Oracle Cloudの生成AIサービスって実際どこまで使えるの? エンジニア目線で試してみた
minorun365
PRO
4
290
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Why Our Code Smells
bkeepers
PRO
335
57k
KATA
mclloyd
29
14k
Optimising Largest Contentful Paint
csswizardry
33
3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
2
170
Faster Mobile Websites
deanohume
305
30k
Making Projects Easy
brettharned
116
5.9k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Transcript
None
Jonathan Reinink Canadian web developer.
A native PHP template system
What is Glide? A wonderfully easy on-demand image manipulation library
written in PHP.
Glide has an HTTP based API. Manipulate images using GET
parameters.
/img/kayaks.jpg /img/kayaks.jpg?w=500 /img/kayaks.jpg?w=500&h=600 /img/kayaks.jpg?w=500&h=600&fit=crop /img/kayaks.jpg?w=500&h=600&fit=crop&filt=sepia
So where did the idea come from? Anyone remember TimThumb?
None
None
It’s a good time for HTTP + PHP. Middleware and
PSR-7 are changing how we build applications in PHP.
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.
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 ] ); });
get('/img/{path}', function ($path) { ! $server = ServerFactory::create([ 'source' =>
'path/to/source', 'cache' => 'path/to/cache', ]); ! $server->outputImage($path, $_GET); });
get('/img/{path}', function (Request $request) { ! $server = ServerFactory::create([ 'source'
=> 'path/to/source', 'cache' => 'path/to/cache', ]); ! $server->outputImage($request); });
get('/img/{path}', function (Request $request, Glide $glide) { $glide->outputImage($request); });
https://vimeo.com/118089742
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), ]);
Set a max image size. Prevent accidental resizing of massive
images.
use League\Glide\ServerFactory; ! $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.
$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.'">';
$templates->registerFunction('img', function ($path, $params) { ! $builder = UrlBuilderFactory::create( 'http://example.com',
'your-sign-key' ); ! return $builder->getUrl($path, $params); });
<img src="<?=$this->img('cat.jpg', ['w' => 500])?>">
<img src="http://example.com/img/cat.jpg? w=500&token=af3dc18fc6bfb2afb521e587c348b904">
$request = Request::createFromGlobals(); $signature = SignatureFactory::create('your-sign-key'); ! try { $signature->validateRequest($request);
} catch (SignatureException $e) { // Handle error }
Resizing.
/img/kayaks.jpg?w=500 /img/kayaks.jpg?h=600 /img/kayaks.jpg?w=500&h=600 /img/kayaks.jpg?w=500&h=600&fit=contain
Cropping.
/img/kayaks.jpg?w=500&h=500&fit=crop
/img/kayaks.jpg?w=500&h=500&fit=crop&crop=left
/img/kayaks.jpg?rect=300,300,810,140
/img/kayaks.jpg?or=90
Adjustments.
/img/kayaks.jpg?bri=-25
/img/kayaks.jpg?con=25
/img/kayaks.jpg?sharp=15
Effects.
/img/kayaks.jpg?blur=10
/img/kayaks.jpg?pixel=10
/img/kayaks.jpg?filt=sepia
/img/kayaks.jpg?filt=greyscale
Output.
/img/kayaks.jpg?fm=gif /img/kayaks.jpg?fm=png /img/kayaks.jpg?fm=jpg /img/kayaks.jpg?fm=jpg&q=90
Extend! Adding your own manipulations.
Moving forward.
Thanks! Follow me on Twitter at @reinink Rate this talk
https://joind.in/13761 Thanks!