$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Lossy PNG for true-color images (Velocity Conf ...
Search
Kornel Lesiński
November 18, 2014
Design
2
890
Lossy PNG for true-color images (Velocity Conf EU 2014)
Kornel Lesiński
November 18, 2014
Tweet
Share
More Decks by Kornel Lesiński
See All by Kornel Lesiński
SudWeb
kornel
0
200
Modern PNG compressors
kornel
13
1.2k
Handling binary data in JS
kornel
1
400
Mobblestouch — W3C Touch Events and gestures
kornel
2
730
Server-Sent Events
kornel
5
970
"HTML5" Transport Protocol
kornel
3
400
Front-end Performance
kornel
5
490
Other Decks in Design
See All in Design
「批評」を習慣にするための仕組みと場のデザイン/uxdesign202507
nikkei_engineer_recruiting
6
950
OJTで学んだ 「心を動かす」ファシリテーション
saki822
1
170
街・都市という眼差し。まちづくりにおける規範と実践
sakamon
1
240
新しいデザインの難しさ(公開版) / Difficulties in the New Design (public ver.)
usagimaru
2
970
Illustrator×Firefly 生成したイラストをベースにドット絵を作ってみよう!
connecre
1
190
ユーザー体験は細部に宿る -ウィジェットQAの挑戦と気づき- / UX is in the details: Challenges and Learnings from Widget QA
bitkey
PRO
0
120
逆向きUIの世界〜AndroidアプリのRTL言語対応〜
akatsuki174
1
660
Spectrum Tokyo_ デザイナーが事業責任者になってみた
shin_2
0
170
保育AIプロダクトの UXデザインで考えてきたこと / hoiku-ai-ux-design
hiro93n
0
230
AIを身近に感じるために、デザイナー全員で一つのサービスを使ってみた
_psyc0_
0
350
Portfolio 齋藤明敏 Hiroyuki Saito
crearedesign
0
130
OSO2025-マサカリと太陽:伝え方の情報デザイン
majimasachi
0
550
Featured
See All Featured
The Cult of Friendly URLs
andyhume
79
6.7k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.3k
Why Our Code Smells
bkeepers
PRO
340
57k
Typedesign – Prime Four
hannesfritz
42
2.9k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.5k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.1k
Building an army of robots
kneath
306
46k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Site-Speed That Sticks
csswizardry
13
990
Making the Leap to Tech Lead
cromwellryan
135
9.7k
Transcript
Lossy PNG Kornel Lesiński 2014
PNG Lossless JPEG Lossy
PNG PNG JPEG Lossless Lossy PNG Opaque Alpha Channel WebP
JPEG 2000 JPEG XR JPEG XT if you need lossy and alpha, it becomes complicated. You may need to serve 4 different files for every image!
flickr.com/photos/ama711/8760361969 0% 100% Lossy PNG is a hack, but it
works like a truly lossy format
Pixels Math gzip Standard PNG
None
gzip finds and removes repeated sequences of identical pixels
00000000 00000001 00000010 00000011 00000100 00000101 00000110 00000111 00001000 00001001
00001010 0 10 110 1110 11110 111110 1111110 11111110 111111110 1111111110 11111111110 → → → → → → → → → → → Instead of storing 8 bits per byte, gzip uses variable-length sequences. Most popular bytes are given shortest sequences.
Some images don’t have repeated pixels and few very popular
colors
0 1 2 3 4 5 6 7 8 9
0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = = Instead of storing uncompressible absolute values PNG can store difference between neighboring pixels
5 6 4 6 5 5 6 4 5 4
5 + 1 -2 +2 - 1 0 + 1 -2 + 1 - 1 = = 5 0 0 0 0 0 0 0 0 0 0 Noisy images won’t compress well… unless you fake the data and remove the noise
Pixels Math gzip Lies Lossy PNG trick is about replacing
math with lies. Only the encoder changes, so it’s 100% compatible.
? When PNG “guesses” what the next pixel will be,
it can make the guess based on average of 2 neighbors, which in lossy PNG causes blur
flickr.com/photos/tundra-ice/5124841152 Original: 2MB 0.6MB 0.3MB
Original: 2MB 0.6MB 0.3MB
Original: 221KB Lossy: 67KB ed_g2s
182KB flickr.com/photos/_tar0_/6223343149
27KB flickr.com/photos/_tar0_/6223343149 The algorithm can decide quality of every pixel,
so it tends to preserve sharp edges, especially text
28KB flickr.com/photos/_tar0_/6223343149 Top of the file has 0% quality, bottom
80% quality
• Works everywhere—fully backwards-compatible • No color limit—supports 24 and
32-bit PNG • Preserves edges—per-pixel quality control • Very fast—small tweak in the encoder • Streamable—only needs 2 lines of the image
pngquant -Q 75-100 --skip-if-larger \ -o out.png in.png || posterize
-b -Q 75 in.jpg out.jpg pngquant is often more efficient, but can’t guarantee quality. You can combine the two for best results.
pngmini.com — ImageAlpha GUI github.com/pornel/mediancut-posterizer CLI logicnet.dk/Analyzer — Image Analyzer
GUI @pornelski pngmini.com/lossypng.html