Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A primer on image optimization

A primer on image optimization

Given at Fastly Altitude in NYC with Edward Thurgood

Ines Sombra

March 22, 2017
Tweet

More Decks by Ines Sombra

Other Decks in Technology

Transcript

  1. Your site img-large im g-thum b im g-thum b im

    g-thum b im g-thum b im g-xs im g-xs
  2. DIY Challenges PROS CONS Open source options available No licensing

    fees Scale as you need Tailor to your needs Setup, hosting, and operability burden on you! Increases stack complexity Costly & takes time
  3. The purpose WIP img-hero im g-thum b im g-xs im

    g-xs im g-thum b im g-thum b im g-thum b
  4. img-hero JPEG 800 × 560 px Quality 85 47 KB vs 2.3MB

    img-thumb 200 × 200 px Quality 85 6.93KB vs 2.3MB
  5. Crop with aspect ratio http://www.fastly.io/gordo.jpg? crop=10:7,offset-x80&width=800 Crop the image square

    & resize the width to 200px http://www.fastly.io/gordo.jpg?crop=1:1&width=200 200 × 200 px Quality 85 6.93KB vs 2.3MB JPEG 800 × 560 px Quality 85 47 KB vs 2.3MB
  6. Features Resizing Cropping / trimming Orientation Quality control Background color

    Resize filters Canvas JPEG Progressive & Baseline PNG 24/32 WEBP Lossy & Lossless Image formats
  7. #

  8. Origin ImageOpto 101 Image Opto Image Opto Image Opto Image

    Opto Image Opto Image Opto Image Opto CDN
  9. Origin ImageOpto 101 Image Opto Image Opto Image Opto Image

    Opto Image Opto Image Opto Image Opto CDN
  10. Origin ImageOpto 101 Image Opto Image Opto Image Opto Image

    Opto Image Opto Image Opto Image Opto CDN
  11. Origin ImageOpto 101 Image Opto Image Opto Image Opto Image

    Opto Image Opto Image Opto Image Opto CDN
  12. Origin ImageOpto 101 Image Opto Image Opto Image Opto Image

    Opto Image Opto Image Opto Image Opto CDN
  13. Origin ImageOpto 101 Image Opto Image Opto Image Opto Image

    Opto Image Opto Image Opto Image Opto CDN
  14. Origin CDN ImageOpto 101 Image Opto Image Opto Image Opto

    Image Opto Image Opto Image Opto Image Opto
  15. Image Opto Image Opto Image Opto Image Opto Image Opto

    Image Opto Image Opto Origin CDN ImageOpto 101
  16. Image Opto Image Opto Image Opto Image Opto Image Opto

    Image Opto Image Opto Origin CDN ImageOpto 101
  17. Origin CDN ImageOpto 101 Image Opto Image Opto Image Opto

    Image Opto Image Opto Image Opto Image Opto
  18. Benefits of Fastly ImageOpto Eliminate your image pre-processing pipeline Seamlessly

    integrated with Fastly’s infrastructure Transformations composable with VCL Cache your large original image and its variations
  19. Our Roadmap Watermarking Increase WebP performance Varnish User Agent detection

    Support more image formats And we’d love to hear us which features you need!
  20. Intro Herman Radtke VP of Engineering at Nordstromrack.com | HauteLook

    Fastly customer for 1 year Beta testing image optimization since May 2016 Nordstrom strives to be the best in Customer Service
  21. Resizing at NRHL Critical for ECommerce to display best image

    for customers. Best means balancing size and quality We used to save different versions of our images on S3 using a python script Later on, we created our own resizer. Problems: Cost a lot We had had to fix bugs Used another CDN's resizer, but we overloaded it. Poor customer experience.
  22. Performance Tests 720 simultaneous servers balanced between North Virginia, Oregon

    and Northern California AWS regions. Wanted to simulate the traffic that would hit the HauteLook home page at 8am ~85 images per server “session” Sustained ~220 resizing requests per second (uncached)
  23. Performance Tests RESULTS 90th percentile - 433ms Average - 243ms

    Max - 4.489s Note: the above measurements include network time
  24. Image Aspect Ratio Best Practice Create high resolution image for

    each aspect ratio. Examples: square, tall, wide Make sure it is large enough! Example: NRHL tall image is 1200 x 1800.
  25. Resizing Examples Resize original image on the fly Original image

    is 960 x 469 /event-hero.jpg?width=480&height=234 Original image URL Add width query parameter Add height query parameter What about that height?
  26. Resizing Examples Odd height numbers 469 / 2 = 234.5

    You can specify just the width and let fastly figure it out! /event-hero.jpg?width=480 Fastly chooses 235 Fastly also accepts percentages Example: /event-hero.jpg?width=50p Put a “p” after the number.
  27. Use Case: Device Scaling Factor Most monitors and smart phones

    are not high resolution. Scaling factor of 1. Many iPhones have better resolution (retina). Scaling factor of 2. iPhone 6 Plus has high resolution. Scaling factor of 3.
  28. Use Case: Device Scaling Factor <img width=200 height=300 src="/6348804.jpg?width=200" srcset="

    /6348804.jpg?width=200&height=300 1x, /6348804.jpg?width=400&height=600 2x, /6348804.jpg?width=600&height=900 3x" >
  29. Use Case: Device Scaling Factor <img width=200 height=300 src="/6348804.jpg?width=200" srcset="

    /6348804.jpg?width=200&height=300&dpr=1 1x, /6348804.jpg?width=200&height=300&dpr=2 2x, /6348804.jpg?width=200&height=300&dpr=3 3x" >
  30. Image Formats Best Practice Use one format! NRHL displays photographs,

    so jpg makes most sense. Change format on the fly: /event-main.jpg?format=webp
  31. API Responses NRHL is API driven. Use a hypermedia API

    format called HAL Image Opto is compatible with URI template RFC 6570. Some resizer formats are not compatible! Example: ?downsize=233:350 Clients (web or app) do not construct URLs They still need some control
  32. API Responses Only set device pixel ratio /hero.jpg?width=200{&dpr} Default to

    automatic webp, allow width /hero.jpg?auto=webp{&width} No URI template parsing library? /hero.jpg?auto=webp&width={width}