Web Images, The Right Way

25
Web Images The Right Way

Transcript of Web Images, The Right Way

Page 1: Web Images, The Right Way

Web ImagesThe Right Way

Page 2: Web Images, The Right Way

Image Formats

Vector

Bitmap

.SVG

.WOFFCSS Shapes

.GIF

.PNG

.JPG

.WEBP

Lossless

Lossy

Page 3: Web Images, The Right Way

Vector vs. Bitmap• Unlimited scalability

• Suitable for “clip art” graphics

• Retina display friendly

• Easy run-time manipulation

• Harder for implementation

• Pixelated or blurry when scaled

• Suitable for realistic photos

• Larger file size for larger resolution

• Not so easy run-time manipulation

• Easy implementation

Page 4: Web Images, The Right Way

Image formats walkthrough

Page 5: Web Images, The Right Way

PNG vs. JPG• Lossless compression

• Support partial transparency

• Efficient for simple shapes & texture

• Suitable for UI elements, logo, screenshots

• Lossy compression

• Only CSS opacity

• Efficient for photorealistic images

• Suitable for images of products, content, photo gallery

Page 6: Web Images, The Right Way

Image Formats

Vector

Bitmap

.SVG

.WOFFCSS Shapes

.GIF

.PNG

.JPG

.WEBP

Lossless

Lossy

Page 7: Web Images, The Right Way

CSS Shapeshttp://codepen.io/daviddcarr/pen/EsLhr

Page 8: Web Images, The Right Way

Icon Fonthttp://icomoon.io/

http://fontawesome.iogulp-iconfont

Page 9: Web Images, The Right Way
Page 10: Web Images, The Right Way

What is Retina Display?

Page 11: Web Images, The Right Way
Page 12: Web Images, The Right Way

Device Pixel Ratio?

Page 13: Web Images, The Right Way

devicePixelRatio = physical pixels / device-independent pixels*

*dips A.K.A CSS pixels, virtual pixels

Page 14: Web Images, The Right Way

Retina Display: devicePixelRatio >= 2

Page 15: Web Images, The Right Way

Web Images & Retina Display

• Use vector images wherever possible• Use @2x bitmap (JPG/PNG) by default• For background images, use between

@1.5x ~ 2x

Page 16: Web Images, The Right Way

Responsive Images

Page 17: Web Images, The Right Way

<picture> <source media="(min-width: 40em)" srcset="big.jpg 1x, big-hd.jpg 2x"> <source srcset="small.jpg 1x, small-hd.jpg 2x"> <img src="fallback.jpg" alt=""></picture>

<img src="small.jpg" srcset="large.jpg 1024w, medium.jpg 640w, small.jpg 320w" sizes="(min-width: 36em) 33.3vw, 100vw" alt="A rad wolf">

Picture element

Image element srcset & sizes

Page 18: Web Images, The Right Way
Page 19: Web Images, The Right Way

Do we need responsive images?

Page 20: Web Images, The Right Way

ImplementationLe

ss e

ffort

More effective

+ srcset w/ polyfill

+ desktop-size images+ @1x images

+ hand-coded res. images

Page 21: Web Images, The Right Way

• 2650px / @2x -> 1400kB

• 1920px / @1.5x -> 822kB

• 1440px / @1x -> 484kB

Most popular desktop size*: 1366x768

• 960px @3x -> 509kB

• 640px @2x -> 249kB

• 320px @1x -> 69kB

* Source: gs.statcounter.com

Photoshop save for web, JPG, 60% quality

Page 22: Web Images, The Right Way

Optimization Tools

Page 23: Web Images, The Right Way

Optimization Tools

• Photoshop Save for Web• ImageOptim• gulp-imagemin• imagemin-cli

Page 24: Web Images, The Right Way

Case Studyhttps://naustud.io/work/2016/11/kuadobox/

Page 25: Web Images, The Right Way

Thank you