the ultimate guide to optimizing website images

62
The Ultimate Guide to Optimizing Website Images Billy Hoffman [email protected] @zoompf

Upload: zoompf

Post on 14-Jul-2015

200 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: The Ultimate Guide to Optimizing Website Images

The Ultimate Guide to Optimizing Website Images

Billy Hoffman

[email protected]

@zoompf

Page 2: The Ultimate Guide to Optimizing Website Images

Bottleneck is the front-end

Back-end Front-end

Page 3: The Ultimate Guide to Optimizing Website Images

HTTP Archive: Feb 2015

Page 4: The Ultimate Guide to Optimizing Website Images

Web is getting heavier…

270 kB

Page 5: The Ultimate Guide to Optimizing Website Images

And it’s mostly images

190! kB

Page 6: The Ultimate Guide to Optimizing Website Images

What’s inside an image?

Page 7: The Ultimate Guide to Optimizing Website Images

Making images smaller

1. Throw out everything you don’t need

2. Store the graphics data more efficiently

3. Reduce the amount graphics data you need to store

Page 8: The Ultimate Guide to Optimizing Website Images

Lossless Optimization• Removes anything not

needed to draw the image

• Better compression

• Optimized image is pixel perfect copy

• Saves 5-20%

• Occasionally 70-80%

Page 9: The Ultimate Guide to Optimizing Website Images

CNN as of 5:45pm

Page 10: The Ultimate Guide to Optimizing Website Images

Whoops

Page 11: The Ultimate Guide to Optimizing Website Images

Junk in the Trunk

Page 12: The Ultimate Guide to Optimizing Website Images

Lossless Optimization (Efficiency)

• Store graphics data more efficiently– Convert GIF to PNG (LZW vs.

DEFLATE)– Beyond stock zlib DEFLATE

implementation

• Optimized image is pixel perfect copy

• Saves 5-20%

Page 13: The Ultimate Guide to Optimizing Website Images

Aside: Always Use PNG

• DEFLATE is superior to LZW

• All browsers support PNG– Those with transparency

issues are near dead

• Only keep animated GIFs

Page 14: The Ultimate Guide to Optimizing Website Images

Never use Animated GIF for Video

• Terrible Compression!

– 10x larger

• Mobile problem

– Dedicated video hardware

Page 15: The Ultimate Guide to Optimizing Website Images

CSS Animation!

Page 16: The Ultimate Guide to Optimizing Website Images

Optimizations: Easy and Scriptable

gif2png -n -O image.gif

pngcrush -brute image.png image-crushed.png

jpegtran -copy none -optimize -perfect -outfile new.jpg orig.jpg

gifsicle -O2 orig.gif -o new.gif

Page 17: The Ultimate Guide to Optimizing Website Images

Don’t forget SVG!

• Just an XML document

• “minify” with scour

– www.codedread.com

• Also HTTP Compression!

Page 18: The Ultimate Guide to Optimizing Website Images

Do it for me…

Page 19: The Ultimate Guide to Optimizing Website Images

Automate it!

Page 20: The Ultimate Guide to Optimizing Website Images

Use the right file format!

Page 21: The Ultimate Guide to Optimizing Website Images

That doesn’t look right

Page 22: The Ultimate Guide to Optimizing Website Images

Digging Deeper

Page 23: The Ultimate Guide to Optimizing Website Images

file is your friend

Page 24: The Ultimate Guide to Optimizing Website Images

file is your friend

Page 25: The Ultimate Guide to Optimizing Website Images

File Formats to Avoid

• BMP

• TIFF

• ICO

Page 26: The Ultimate Guide to Optimizing Website Images

Losing Graphics Data?

If 80-95% of the bytes in an image are graphics data…

… perhaps we should look at reducing the size of the graphics data

Lossy Optimizations!

Page 27: The Ultimate Guide to Optimizing Website Images

“Do Not Touch My Art!”

• Lots of push back

• “Losing” data is scary

• “Won’t that look bad?”

• “We spent a long time to make it look like this.”

Page 28: The Ultimate Guide to Optimizing Website Images

Everything is Lossy!• Telephone calls (8kHz w/ 8bit Samples)• CDs (44kHz w/ 16 bit samples)• Conversion to Color Television

– Eye more sensitive to brightness than color– Chroma Sub-sampling (Y’CbCr 4:2:2)– 33% less bandwidth, no perceivable difference

• MP3 files– Frequency Masking

Page 29: The Ultimate Guide to Optimizing Website Images

… In the Eye of the Beholder

• This is all subjective!– “Noticeable”– “Perceptible”– “Nearly the same”

• Beware *philes– CDs vs. Vinyl– MP3 vs. FLAC

• Find a middle ground for average viewer

Page 30: The Ultimate Guide to Optimizing Website Images

PNG24 to PNG8

• From millions of colors to 256

• The human eye is not well suited to detecting subtle color changes

• Discard them!

Page 31: The Ultimate Guide to Optimizing Website Images

Reasonable Number of Colors (65%!)

PNG24Size: 77 KBColors: 12,769

PNG8Size: 26 KBColors: 256

Page 32: The Ultimate Guide to Optimizing Website Images

Differences

Page 33: The Ultimate Guide to Optimizing Website Images

What About Lots of Colors?

PNG24Size: 512 KBColors: 148,279

PNG24Size: 188 KBColors: 256

63% smaller

Page 34: The Ultimate Guide to Optimizing Website Images

Differences

• 99.82% less colors!

• Skin tone transition is not smooth…

• Only noticeable on larger images or extreme zoom

Page 35: The Ultimate Guide to Optimizing Website Images

Smaller Images

PNG24100 x 100Size: 19 KBColors: 9,138

PNG8100 x 100Size: 8 KBColors: 256

55.8% smaller

Page 36: The Ultimate Guide to Optimizing Website Images

PNG24 to PNG 8 Guidelines• Convert images with low unique color counts and verify

– identify –format "%k“ image.png– Zoompf recommends < 5000 colors

• Always convert small dimensional images– Zoompf recommends < 10,000 pixel area

• Tools– Pngquant (the new version)– Imagemagick– Zoompf free scan/WPO

Page 37: The Ultimate Guide to Optimizing Website Images

PNG24 to PNG8: Caveats

• Tool support for alpha transparency

– Online converter

• Not always smaller for small images

Page 38: The Ultimate Guide to Optimizing Website Images

Lossless to Lossy (PNG to JPEG)• Lots of images are saved as lossless when lossy

will work– Photos– Screen shots– Logos– Icons– Diagrams

• Changing formats reduces file size

Page 39: The Ultimate Guide to Optimizing Website Images

Obvious: Photographic Data

PNG24Size: 512110Colors: 148279

JPEGSize: 52015Colors: 72060

89% smaller

Page 40: The Ultimate Guide to Optimizing Website Images

Logos/Icons/Buttons

PNG24Size: 35503Colors: 728

JPEGSize: 16123Colors: 12224

55% smaller

Page 41: The Ultimate Guide to Optimizing Website Images

Backgrounds

PNG241623 x 967Size: 76 KB

JPEG1623 x 976Size: 33 KB

56% Savings

Page 42: The Ultimate Guide to Optimizing Website Images

90% Savings!!!

Backgrounds

PNG24320 x 568Size: 100 KB

JPEG320 x 568Size: 10 KB

Page 43: The Ultimate Guide to Optimizing Website Images

Figures/Line art?

• PNG is supposed to be better than JPEG

PNG241623 x 967Size: 76 KB

JPEG1623 x 976Size: 33 KB

56% Savings

Page 44: The Ultimate Guide to Optimizing Website Images

Figures/Line art?

• Transition artifacts are remarkably low impact

Page 45: The Ultimate Guide to Optimizing Website Images

PNG to JPEG Caveats

• Different formats with different features

• Transparency– JPEG does not support it

– Not as big of a deal as you think

– Flatten onto background color

– convert input.png –background white –flatten output.JPEG

• Generational losses– Don’t keep editing the same JPEG…

Page 46: The Ultimate Guide to Optimizing Website Images

PNG to JPEG Guidelines• Review images to discover what is PNG and what

is JPEG– .jpg does not mean JPEG…– Imagemagick’s identify, Linux/Unix’s file

• Bulk convert and verify– Tedious

• Only consider when savings > 30%– Zoompf free scan/WPO flags these candidates

Page 47: The Ultimate Guide to Optimizing Website Images

JPEG Quality• JPEG images have a “quality” setting

– 1-100– 0-10

• Quality 90 != discarding 10% of data• Quality scale is purely arbitrary

– it's not a percentage of anything

• Best Practices for web– 50-80, 75, depends on source

Page 48: The Ultimate Guide to Optimizing Website Images

Reducing JPEG Quality

JPEGSize: 52 KBQuality: 85

JPEGSize: 37 KBQuality 75

29% smaller

Page 49: The Ultimate Guide to Optimizing Website Images

Going Further

JPEGSize: 52 KBQuality: 85

JPEGSize: 23 KBQuality 50

55% smaller

Page 50: The Ultimate Guide to Optimizing Website Images

Differences

• Differences– Some blurring– Feather edges affected– Only visible when zoomed

• Quality 50:– little differences

• Quality 75:– Virtually no differences

Page 51: The Ultimate Guide to Optimizing Website Images

Smaller Images

JPEG100x100Size: 3,964 bQuality: 85

JPEG100x100Size: 2,159 bQuality: 50

46% smaller

Page 52: The Ultimate Guide to Optimizing Website Images

Real Life: Facebook

• All those thumbnails?

• 95 Quality!

– Seriously. 95!

• Reducing to 70?

– 44% Savings!

Page 53: The Ultimate Guide to Optimizing Website Images

Zoompf Savings Table

Page 54: The Ultimate Guide to Optimizing Website Images

JPEG Quality Guidelines• if q> 85

– Reduce to 85 always (> 90 has no benefits)– Consider Q 75 if it saves more than 30%

• If pixel area < 10,000– Always reduce to 60. Lower if possible

• Consider tweaking– Blurs, softens, sharpens, etc

• Tools– WebPageTest, Zoompf. Imagemagick

Page 55: The Ultimate Guide to Optimizing Website Images

• Raster File Format

• Both Lossy and Lossless

• Derived from WebM

• Supported on by Chrome

– Desktop

– Andriod

Page 56: The Ultimate Guide to Optimizing Website Images

Still! The Mobile Problem

• Modern chips have dedicated hardware

• JPEGs/PNG

• H.264

Page 57: The Ultimate Guide to Optimizing Website Images

Conclusions

• Images dominate the web– In Size– In Count

• Image domination is growing larger

• Huge, untapped area, needs more attention

Page 58: The Ultimate Guide to Optimizing Website Images

Conclusions

• Lossless gives 5-20%. No brainer!

• Don’t be scared about lossy– Be intelligent about how you

apply lossy

• Lossy achieves substantial savings– 40-60%, 80% spikes

Page 59: The Ultimate Guide to Optimizing Website Images

Lossless Guidelines Summary

• Always use the correct format

• PNG (pngcrush)

• JPEG (jpgtrans, jpgcrush)

• Avoid GIF completely (gif2png + pngcrush)

– gifsicle or just use a photo

Page 60: The Ultimate Guide to Optimizing Website Images

Lossy Guidelines Summary• PNG24 to PNG8

– When < 5000 colors– When < 10,000 pixel area

• PNG to JPEG– Per case, apply when > 30% savings

• JPEG Quality– Target a 70-85 quality settings– Always 50-60 when for < 10,000 pixel area

Page 61: The Ultimate Guide to Optimizing Website Images

Free Tools: Zoompf Alerts Beta• Continuously scanning

and alerting

• Free, in Beta– zoompf.com/alerts

• Also… Standard Free Report– zoompf.com/free

Page 62: The Ultimate Guide to Optimizing Website Images

The Ultimate Guide to Optimizing Website Images

Billy Hoffman

[email protected]

@zoompf