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
Using ImageMagick to resize your Images [FSTO]
Search
newtron
April 08, 2015
Technology
470
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Using ImageMagick to resize your Images [FSTO]
Full Stack Toronto,
2015-04-08
https://github.com/nwtn/pres-imagemagick-fsto
newtron
April 08, 2015
More Decks by newtron
See All by newtron
Universal web design [Accessibility Camp Toronto]
newtron
0
250
Universal web design [HackerYou a11y club]
newtron
0
230
Universal web design [Full Stack Toronto]
newtron
0
280
Information architecture as knowledge translation [World IA Day]
newtron
0
310
Improving performance with responsive (and responsible!) images [CSSDay.io]
newtron
1
410
Universal Web Design: How to create an awesome experience for every user [Open Source Bridge]
newtron
0
300
Improving performance with responsive (and responsible!) images [CSSConf]
newtron
6
730
Universal Web Design: How to create an awesome experience for every user [OpenWest]
newtron
0
300
Improving performance with responsive (and responsible!) images [OpenWest]
newtron
2
390
Other Decks in Technology
See All in Technology
How Timee Delivers Day 1 Production Ready LLM Features
tomoyks
0
150
失敗を資産に変えるClaude Code
shinyasaita
0
540
Amazon Bedrock AgentCore ワークショップ JAWS UG TOHOKU / amazon-bedrock-agentcore-workshop-jawsug-tohoku-2026
gawa
9
740
NAB Show 2026 動画技術関連レポート / NAB Show 2026 Report
cyberagentdevelopers
PRO
0
170
ルールやカスタム機能、どう活かす?ハンズオンで体感するIBM Bobの出力コントロール
muehara
1
130
2026TECHFRESH畢業分享會 - 原生還是跨平台? App 開發踩坑實錄
line_developers_tw
PRO
0
880
やさしいA2A入門
minorun365
PRO
12
1.8k
ACE-Step-1.5で見る 音楽生成AIのしくみと“破綻だけ直す”Retake機能の開発【zennfes spring 2026 登壇資料】
personabb
1
140
SONiC Scale-Up Working Group から探る Scale-UpやUltraEthernet機能の実装方法
ebiken
PRO
2
130
AIっぽい文章を採点して人間らしく直すアプリを作ってみた
yama3133
2
130
なぜ Platform Engineering の土台に Kubernetes を選ぶのか
r4ynode
2
590
2026TECHFRESH畢業分享會 - Lightning Talk - 資料也要 CI/CD? 用 Airbyte 自動化資料同步
line_developers_tw
PRO
0
860
Featured
See All Featured
HDC tutorial
michielstock
2
700
Testing 201, or: Great Expectations
jmmastey
46
8.2k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
270
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
420
The Pragmatic Product Professional
lauravandoore
37
7.3k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
250
Evolving SEO for Evolving Search Engines
ryanjones
0
210
Everyday Curiosity
cassininazir
0
230
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Transcript
David Newton, St. Michael’s Hospital 1 1 Using ImageMagick to
resize your Images Full Stack Toronto, 2015-04-08 Twitter: @newtron Github: @nwtn Email:
[email protected]
Slides + image credits: https://github.com/nwtn/pres-imagemagick-fsto
2
3 Responsive images are a pain in the butt
4
5
6
7 ImageMagick, y’all
8
9 $ brew install imagemagick
10 Condition (unoptimized input) File size: mean File size: %
difference Photoshop CC, with optimization 260,305 bytes ImageMagick `-resize` 385,795 bytes 48.21%
11 How does image resizing work?
12 685,936 pixels 189,739 pixels
13 …to 64 pixels? How do we get from 16
pixels…
14 != resampling
15 …to 64 pixels? How do we get from 16
pixels…
16 …to 64 pixels? How do we get from 16
pixels… Background interpolation
17 …to 64 pixels? How do we get from 16
pixels… Nearest-neighbour interpolation
18 Nearest-neighbour interpolation
19 Bicubic interpolation
20 Nearest-neighbour vs. bicubic interpolation
21 7 colours 1,146 colours
22
More colours = More bytes* 23
24 https://github.com/nwtn/image-resize-tests/
25 How do we know which options are best?
Quality objective: measured with DSSIM 26
27 Control Test Difference
28
Quality subjective: from me 29
Test a variety of images 30
31 The best* settings for ImageMagick
32 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.08+8.3+0.045 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB INPUT_PATH With optimization:
33 https://github.com/toy/image_optim https://github.com/ajslater/picopt https://imageoptim.com/
34 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH Without optimization:
35 mogrify vs. convert
36
37 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH
38 resampling filter
39 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH
40 Adaptive resize Distort resize Geometry Interpolative resize Liquid rescale
Resize Sample Scale Thumbnail
41 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH
42
43
44 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH
45
46 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH
47 Fancy
48 sharpening
49 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH
50 -unsharp 0.25x0.25+8+0.045 radius sigma gain threshold
51 -unsharp 0.25x0.25+8+0.045 radius sigma gain threshold
52 colour reduction
53 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH
54
55
56
57
58
59 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -colors NUMBER_OF_COLORS -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH If output file size is larger than input:
60 7 colours 1,146 colours
61 7 colours 7 colours
62 quality and compression
63 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH
64 quality 10 quality 40 quality 70 quality 100
65 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH
66 metadata
67 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH
68 progressive rendering
69 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH
70
71
Progressive JPEGs Good? Evil? 72
73 colour space
74 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH
75
76 The best* settings for ImageMagick
77 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.08+8.3+0.045 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB INPUT_PATH With optimization:
78 mogrify -path OUTPUT_PATH -filter Triangle - define filter:support=2.0 -thumbnail
OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None - posterize 136 -quality 82 -define jpeg:fancy- upsampling=off -define png:compression-filter=5 - define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude- chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH Without optimization:
79 Why even bother?
80 Condition (unoptimized input) File size: mean File size: %
difference My settings, optimization 218,274 bytes My settings, no optimization 259,852 bytes 19.05%
81 Condition (unoptimized input) File size: mean File size: %
difference My settings, optimization 218,274 bytes My settings, no optimization 259,852 bytes 19.05% Photoshop CC, optimization 260,305 bytes 19.28% Photoshop CC, no optimization 299,710 bytes 35.26%
82 Condition (unoptimized input) File size: mean File size: %
difference My settings, optimization 218,274 bytes My settings, no optimization 259,852 bytes 19.05% Photoshop CC, optimization 260,305 bytes 19.28% Photoshop CC, no optimization 299,710 bytes 35.26% basic `-resize` / WordPress* 385,795 bytes 76.75%
83 Condition (unoptimized input) File size: mean File size: %
difference My settings, optimization 218,274 bytes My settings, no optimization 259,852 bytes 19.05% Photoshop CC, optimization 260,305 bytes 19.28% Photoshop CC, no optimization 299,710 bytes 35.26% CodeIgniter / ExpressionEngine 340,461 bytes 55.98% TYPO3.CMS* 359,112 bytes 64.52% basic `-resize` / WordPress* 385,795 bytes 76.75% Drupal* 397,588 bytes 82.15% Perch* 416,790 bytes 90.95% Craft CMS* 425,259 bytes 94.83% grunt-responsive-images* 500,273 bytes 129.20%
84 PHP Imagick
85
86
87 CLI Imagick DSSIM File Size -filter N/A N/A N/A
-define filter:support setOption() ? ? -thumbnail thumbnailImage() ✗ ✗ -unsharp unsharpMaskImage() ✔ ✔ -dither & -posterize posterizeImage() ✔ ✔ -quality setImageCompressionQuality() ✔ ✗ -define jpeg:fancy-upsampling setOption() ✔ ✔ -define png:compression-filter setOption() ✔ ✔ -define png:compression-level setOption() ✔ ✔ -define png:compression-strategy setOption() ✔ ✔ -define png:exclude-chunk setOption() ✔ ✔ -interlace setInterlaceScheme() ✔ ✔ -colorspace setColorspace() ✔ ✔ -strip stripImage() ✔ ✔
88
89 CLI Imagick DSSIM File Size -filter custom ✔ ✗
-define filter:support setOption() ✔ ✗ -thumbnail custom ✔ ✗ -unsharp unsharpMaskImage() ✔ ✔ -dither & -posterize posterizeImage() ✔ ✔ -quality setImageCompressionQuality() ✔ ✔ -define jpeg:fancy-upsampling setOption() ✔ ✔ -define png:compression-filter setOption() ✔ ✔ -define png:compression-level setOption() ✔ ✔ -define png:compression-strategy setOption() ✔ ✔ -define png:exclude-chunk setOption() ✔ ✔ -interlace setInterlaceScheme() ✔ ✔ -colorspace setColorspace() ✔ ✔ -strip stripImage() ✔ ✔
90 OK… but it’s still a pain in the butt
91 https://github.com/nwtn/php-respimg/ Resizing with smart defaults + more coming soon?
92 $ composer require nwtn/php-respimg
93
94 https://www.npmjs.com/package/grunt-respimg Resizing with smart defaults SVG to PNG rasterization
Optimization
95 $ npm install grunt-respimg --save-dev
96
97
David Newton, St. Michael’s Hospital 98 Using ImageMagick to resize
your Images Full Stack Toronto, 2015-04-08 Twitter: @newtron Github: @nwtn Email:
[email protected]
Slides + image credits: https://github.com/nwtn/pres-imagemagick-fsto