Kelly Thompson
December 22, 2024
•
5 min read
I was listening to Accidental Tech Podcast Episode 618, and it was one of those times when you’re yelling at the podcast hosts. The question came up about how much space converting current JPEG files in the Photos Library file to JPEG XL (leaving aside whether doing it or not was a good idea). Turns out I’d already built a script that calculated just that. The lossless conversion from JPEG to JPEG XL saves almost exactly 20%.
Here’s the script that calculates just the total size of all JPEG files:
find '/path/to/your/Photos Library.photoslibrary' -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -ls | \
awk '{total += $7}
END {
printf "Total: %.2f GB\n", total/1024/1024/1024;
printf "Assuming a savings of 20%%, you'\''d reclaim ~%.2f GB\n", (total/1024/1024/1024) * 0.2
}'
Mine came out to:
Total: 134.42 GB
Assuming a savings of 20%, you’d reclaim ~26.88 GB
I know most of us could certainly use that kind of drive space back in our lives… and on our drives.
If you’d like to see each file size that it adds, this one includes that (but takes much longer to run):
find '/Users/kelly/Pictures/Photos Library.photoslibrary' -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec stat -f "%z %N" {} \; | \
awk '{size = $1/1024/1024; total += size; printf "%.2f MB %s\n", size, substr($0, index($0,$2))}
END {
printf "\nTotal: %.2f GB\n", total/1024;
printf "Assuming a savings of 20%%, you'\''d save ~%.2f GB\n", (total/1024) * 0.2
}'
I agree with the ATP cast though – doing this outside of Apple’s control might be a little nerve-racking. Maybe an app like PowerPhotos (highly recommended, BTW) could take it on before Apple does. What would be even more impressive is if it allowed not just lossless recompression, but lossy compression. You’d get massive savings and prety much gurantee you couldn’t see the difference (especially at -d 1
using cjxl
, as it’s visually lossless). Sounds like a job for John Siracusa’s new line of space-saving apps!
While I haven’t attempted this on my Photos library, I certainly have on folders full of JPEGs and PNG files I’ve saved over the years. For those not adept at the command line, you can use this to convert a folder of PNGs or JPEGs. Note this is using -d 1
(targeting visually lossless results) for its compression level. If you want a lossless JPEG transcode, change to -d 0
.
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec sh -c 'cjxl -d 1 -e 9 "$0" "${0%.*}.jxl"' {} \;
If you’re a brew user (and what Mac geek isn’t), and you’ve installed parallel
, use this to make things much faster:
parallel cjxl --num_threads=0 -d 0 -e 9 {} {.}.jxl ::: /your-directory/*.png
Note this example is using -d 0
for lossless compression on all PNG files in the folder. Change as required. Also it doesn’t touch the originals, so compare to see if you’re happy with the results.
Also, this all assumes you’ve installed the JPEG XL library libjxl
. If you haven’t:
brew install jpeg-xl
If you haven’t installed parallel
, use:
brew install parallel
Remember, -d 0
is lossless. Anything -d 1
or less is visually lossless (but you can probably cheat even higher). You can save lots of time by doing effort -e 7
instead of -e 9
with (likely) little difference in savings.
Besides savings boatloads of room in the Photos App, I wonder if developers are realizing they can use JPEG XL inside their apps. Replacing PNGs with JPEG XLs is a big deal – bigger than JPEG recompression. ATP crew, make that happen!
NB: I use fish as my command line shell and iTerm as my terminal. Results may vary, so be careful using any of these commands. Also this assumes your photos are local on your machine. Not sure the outcome if they aren’t!