Raster Image Optimization with Squoosh.app
Homework
- Image Formats and Compression
- Watch: Image compression deep-dive by Jake and Surma
- Read:
picture
element - Reference: Image file type and format guide
- Tool: Squoosh.app
Morning reflection
Housekeeping
- Draft:
cpnt201-a2
- Lab time agendas
- Changes to Dailies
- New attendance process?
1. Image theory
Learning Objectives
- Define image encoder.
- Distinguish between lossless, lossy compression.
- Distinguish between high and low frequency imagery.
- Predict whether lossless or lossy compression will be best for a particular image.
Terminology
- Image encoder (aka. codec)
- A library/module that converts one image format to another. Not all encoders are created equal.
- Colour Data (aka. chroma)
- The digital information in an image that controls pixel colour. Also called chroma data.
- Brightness Data (aka. luma)
- The digital information in an image that controls pixel brightness.
- High Frequency Imagery
- Parts of an image (or the whole image) where colour and contrast change a lot from one pixel to the next. Example: a photo of nature (trees, mountains, etc.).
- Low Frequency Imagery
- Parts of an image (or the whole image) where colour and contrast change very little from one pixel to the next. Example: a vector logo or other image with a lot of flat colour.
- Sample Images
- Video breakdown: Image compression deep-dive
- 0:00 - Intro
- 1:49 - Lossy vs lossless vs vector
- 4:45 - Lossy: Chroma vs Luma
- 8:03 - Lossy: How JPEG works
- 12:47 - “WebP is just better.”
- 16:04 - Squoosh feature walk-through (lossy)
- 21:28 - Lossless: Stop using GIF
- 23:00 - Squoosh feature walk-through (lossless)
- 27:38 - Review and conclusion
- Don’t rely on Photoshop’s image codecs (Squoosh is way better).
- Lossy image encoders shrink the file size of an image by throwing away colour data while keeping brightness data.
- Lossless image encoders shrink file size by indexing the colours in an image and then mathematically “describing” each pixel based on their neighbours (i.e. “the next 159 pixels are white”).
- If you need to support older browsers:
- JPEG (lossy) is best for high frequency images;
- PNG (lossless) is best for low frequency images.
- Get you an encoder that can do both (WebP). Use the
picture
element to use WebP images with a JPEG/PNG fallback. This allows you to use other codecs as well. - Don’t zoom in!
- Create an optimized high frequency image using the WebP (lossy) codec.
- Create an optimized high frequency image fallback using the
MozJPEG
codec. - Create an optimized low frequency image using a WebP (lossless) codec.
- Create an optimized low frequency image fallback using the
OxiPNG
codec. - Pick a high frequency image (try jank and upload it to Squoosh.
- Zoom the image to the size it will be on the web page (and resist the urge to zoom).
- To account for high resolution displays, take the native size of your image and zoom out so it’s about 50% of its original size.
- Choose
WebP
encoder under “Compress”. - Turn down Quality until the image “looks bad”.
- Increase Effort (to max?).
- Advanced Settings:
- try toggling
Auto adjust filter strength
; - try adjusting
Spatial noise shaping
.
- try toggling
- Download and save your optimized files in a
full
directory next to yoursource
directory. - Choose
MozJPEG
encoder under “Compress”. - Reduce
Quality
until the image “looks bad”. - Advanced Settings:
- try adjusting
Subsample chroma by
; - try toggling
Separate chroma quality
.
- try adjusting
- Download the optimized image and use it as an asset in a project web page of your choice.
- Complete two performance audits on your project page using Chrome Lighthouse: once with the original image file and a second with the optimized image file.
- Download and save your optimized files in a
full
directory next to yoursource
directory. - Pick a low-frequency image (something with a lot of flat colour) and upload it to Squoosh.
- Zoom the image to the size it will be on the web page (and resist the urge to zoom).
- To account for high resolution displays, take the native size of your image and zoom out so it’s about 50% of its original size.
- Choose
WebP
encoder under “Compress”. - Click
Lossless
to enable the low-frequency encoder. - Increase
Effort
(to max?). - Try increasing
Slight loss
. Your mileage may vary. - Try
reduce pallette
to remove unneeded colours.- Select
Browser PNG
under “Compress” to speed up the preview. - Click
Reduce pallette
. - Reduce
Dithering
to zero (unless you need it, which you probably don’t). - Reduce
Colors
as much as possible until the image “looks bad”.
- Select
- Download and save your optimized files in a
full
directory next to yoursource
directory. - Choose
OxiPNG
encoder under “Compress”. - Increase
Effort
(to max?). - Click
Reduce pallette
. - Reduce
Dithering
to zero (unless you need it, which you probably don’t). - Reduce
Colors
as much as possible until the image “looks bad”. - Download and save your optimized files in a
full
directory next to yoursource
directory. - Does WebP provide enough savings to bother with it?
- Define the low and high frequency areas;
- Predict if the file will be smaller as a lossless or lossy image.
- Use Squoosh to see if you’re correct.
- Finalize cpnt201-a2.
- Play with clip-masks.
- Submit today’s Codepen/repo/gist to the Dailies section (in Assessments) in Brightspace.
Materials
Key Takeaways
2. Image Optimization with Squoosh.app
Materials
Learning Objectives
Activity 1: Squooshing high-frequency images with WebP (Lossy)
Optimize an image file size using Squoosh.app:
Activity 2a: Creating JPEG image (for Safari)
Activity 3: Squooshing low-frequency images with WebP (Lossless)
Activity 3a: Creating PNG image for Safari
Open lab-time
Using the large images you created yesterday: