Making compact image files
Before embedding images in a web page or a pdf, it’s often a good idea to make sure they have a reasonable file size. You can also attempt to compress PDFs after they have been produced.
Shrink large images to be the size in pixels that you want to display. Image editors often resample images better than a web-browser will on the fly, so the images will look better and be quicker to download.
Use an appropriate image format. Generally use JPEG for photos, PNG for line-art. There are exceptions: if line-art has gone through JPEG and the original has been lost, it may be better to leave it as JPEG as the compression artifacts will mess up PNG compression.
Sometimes reducing the number of colours in a PNG file may help improve filesize without noticably changing the image.
The following utilities losslessly improve the compression in image files, sometimes dramatically:
- Animated GIFs: use gifsicle. Use “-b -O2” to fully optimize a file in place.
- PNGs: use optipng.
- PNGs: if really obsessed also get advancecomp and PNGOut and run my wrapper “pngsquish” that runs all of them.
- JPEGs: use jpegoptim.
- EPS or PDF of a raster image: use sam2p.
- APNG Optimizer.