Okay. You’ve just painstakingly put 10 posters into a scanner and you now have your 600dpi TIFF file. It’s pretty big. It doesn’t have to be this big.
“Why should I compress my scans? I just want to get them out so people can use them and they can do all the funky stuff from there!”
During the making of this document, I had to download 1-2gb scans from archive.org, which will throttle your speeds to 1MB/s after a minute. To get around this, you can use bulk downloading tools, but that requires a decent more amount of setup and know-how than clicking the download button. This is where compression comes in. This guide will utilize non-destructive lossless compression tools to get your filesize down to something much more manageable in a few extra steps.
Brief format overview
- TIFF: Image format developed by Adobe in 1986 to unify output formats from scanners. It can offer compression, but it’s an old format and has been obsoleted by modern formats. This is usually the best non-lossy format you will have available to you on a scanner.
JPEG: Lossy image format released in 1992 by MPEG. The reigning champion of compression to quality until around 10 years before now, but is unsuitable for archival since the corners it cuts to achieve this ratio are lossy and thus irreversible.
- PNG: Lossless image format released the same year as JPEG. The reigning champ of pretty much every use case for images thanks to it utilizing DEFLATE (same as PKGZIP) compression, and thus extremely optimizable. Thanks to being lossless you can do a variety of mathematical transactions to it without losing any image data.
- WebP and AVIF: Open source formats mainly developed by Google, based off of VP9. I won’t touch on these much, but since they both offer lossless and lossy modes and are well adopted by the open source ecosystem, they’re worth mentioning. Given the existence of JXL and the strength + adoption of PNG, I do not believe they are worth using over either, though both will work in browsers while JXL currently will not due to industry stalling. If you want compatibility, then... use PNG. If you want compatibility and modern compression ratios, try AVIF or WebP.
- JPEG XL (JXL): Various lossless image formats have been designed to replace both JPEG and PNG, but the one that has gained the most momentum is JPEG XL. Work from several of the top lossless codecs was consolidated to create it, working with MPEG to develop it as the new (and open) standard. Currently the best option for losslessly compressing files easily, though the industry is straggling to adopt it. JXL also has a hybrid option to include both a JPEG-compatible output and a full JPEG XL image. That’s beyond the scope of this guide, for now. Currently not feasible for most computers to convert very large (over 10000x10000 pixels) image files, just do PNG.
The process
After getting your raw image files to your computer, the immediate next step is to convert to PNG. PNG is good enough for all use-cases and if you’re sending these files to someone non-technical you won’t need to do much else. You can optimize the filesize further (and I would encourage you do so if you have the time) if PNG will be your final format, but my archival recommendation is to go straight to JXL if no other image restoration work is needed. Why? Because you get the same compression gains as you would using various PNG optimization tools with JXL cranked up to its highest preset, using up way less of your time. However, if your image is very large (over 10000x10000 pixels) and you don’t have 100 gigs of ram, encoding to JXL will outright crash as you run out of memory with current tooling. You can safely stay with PNG in this case.
Let’s convert to PNG first. Since it’s a cross platform solution, is free and is translated to many languages, I’ll be using GIMP. You can also use Photoshop, if you have it.
- Open your file. Top left; File, Open. Select your uncompressed input file. It’ll ask you to convert the color profile. Select Keep.
- After that, your file should be loaded and you should see it in your workspace. If there’s a progress bar at the bottom, give it some more time.
- To export to PNG, all you need to do is go top left, click File, Export As. Set the filename to be NameOfYourImage.png. Do not click Save or Save As.
- From there, just click export at the bottom right.
- The default options, as pictured below, are all you need.
- Click Export one more time and your file will start compressing. Congrats! You’re done.
For command line users, you can do my preferred way of converting to PNG with the command line utility vips. It’s available in many package managers across many platforms as vips-tools. Package name might differ, but it’s likely to be there. Make sure you download the vips command line tool and not libvips by itself. If you don’t have vips available to you, you can use ImageMagick or even FFmpeg.
All you need to do to convert your image with vips is to use the following command:
$ vips --vips-progress pngsave InputImage.tiff CompressedImage.png –compression 9
That’s it! You’re done.
Saving Extra Space
I know, I said “you’re done”. But if your final format is PNG, there’s a lot of tools out there that can optimize your image using lossless algorithms to save a huge amount of space. And if you’re reading a guide on how to compress your scans I’m hoping you’ll find this informative and/or useful.
There are a variety of GUI and web tools that’ll make this pretty easy for you. There’s a list of good ones on the site for ImageOptim, a good MacOS GUI compression app. If you’re on Windows, try Pinga. My favorite tool is the CLI tool oxipng.
Safe defaults for large images: $ oxipng --fast --strip safe --out CompressedImage.png InputImage.png
The most compression possible: $ oxipng -o max --fast -Z --strip safe --out CompressedImage.png InputImage.png
JPEG XL
It’s important to note that if you’re sending your scans to someone else that is not familiar with these advanced tools to do the often-necessary cleanup tasks in Photoshop and the like, just send them PNGs. You can send them this guide if they will be doing final distribution.
If you have an image that’s small enough or if your computer has enough RAM (until streaming support is added to vips/libjxl is prepared for cases like this) then convert your image to JPEG XL. You can do it via GIMP on all platforms following the steps for PNG but setting the output filename to NameOfYourImage.jxl instead of NameOfYourImage.png. Just make sure you select Lossless Mode!
In the unfortunate (but likely) case that your version of GIMP will throw you an error, it is best to resort to command line utilities. I’ll show examples using vips and libjxl’s reference conversion program.
$ vips --vips-progress jxlsave InputImage.tiff CompressedImage.jxl --lossless --distance 0
$ cjxl -p -q 100 InputImage.png CompressedImage.jxl
(libjxl does not support importing from TIFF)
To get JPEG XL files back into PNGs or other formats, you can use those same utilities above.
$ vips --vips-progress pngsave CompressedImage.jxl CompressedImage.png –compression 9
$ djxl CompressedImage.jxl CompressedImage.png