Bulk compressing PNG images to save storage space

I have a deck with TONS of PNG images in it (about 150gb). I want to compress them to help save storage space but need to maintain as high image quality as I can even though l’m compressing.

It doesn’t seem like there is an anki addon that will accomplish my goal. As such, I found this website (compressimage), which seems like it does a good job at compressing images while maintaining good quality.

I’m open to any other recommendations if people have them though.

I was hoping I could just drag and drop my Anki media folder into the above program and it will compress all the images at once. But afterwards how would I get all of these new compressed images to replace the images on my original cards with the same formatting and everything (eg, location of image on the card, line breaks between images, etc.)? Also, what is the best way to keep a backup of my Anki collection with the original images if something goes wrong during this process?

Any suggestions/advice is appreciated. Thanks!

1 Like

Thanks for your response. How does changing PNG to WebP affect the quality of the image? I like the idea of reducing the storage space like that but I also really need the images to maintain as much quality as possible too, which I know is a difficult balance.

You can use this add-on to bulk convert all PNG images to webp or avif (remember to back up your media folder first)

You can make a backup of your media folder simply by copying the contents in your folder to another one (simply make a copy of it)

AJT Media Converter / WebP, AVIF

WebP lossless images are 26% smaller in size compared to PNGs. WebP lossy images are 25-34% smaller than comparable JPEG images at equivalent SSIM quality index

In settings, you can add this option to try to maintain as much quality as possible while reducing file size

when converting PNGs to WEBP, it makes sense to add -lossless and -q 100 options.

Less quality = More storage space

Worked well. Reduced filesize of the .colpkg by 10% even with it set to 90% quality.

A wonderful add-on, in general saves me around 50-70% of disk space

I love this plugin! Works well both in the editor (while pasting images) and in batch conversion mode to optimize the existing collection.
It helped me reduce the size of images in my media folder from 435 MB to 165 MB without any perceivable difference in quality during reviews :slight_smile:

how much % space will this save?
depends on your settings, but you can reduce the size by as far as 9 times, though the image quality will suffer.

About AVIF

2 Likes

Thanks for sharing this add on. It looks promising. Have you used this before? If so, what settings do you recommend? Also, does this add on make the image physically smaller? I don’t necessarily want the image to be physically smaller, rather I just want the file size of each image smaller while still maintaining the same physical size and hopefully maintaining quality that is not significantly different to the human eye.

This is a must have add-on for me, i use for every image at 85% quality 1080x1080

you shouldn’t touch height and weight if you don’t want to decrease the image ratio, just the quality

hopefully maintaining quality that is not significantly different to the human eye

You will be looking at > 85% then, remember the less quality, the more you will save


Here the difference between PNG and WebP at 85%, 1080×1080 (Pixorize images are an exception)

Check the file size and the image difference between webp and png
https://drive.google.com/drive/folders/1T0mzRSy7Nz9hyJqjkkwgklJArJK3kFyW

Nice. Thanks for sharing those examples. How much space did that end up saving you after converting to WebP at 85%?

4.3GB to 1.3GB
See Decreasing the total size of images in the AnKing Step Deck - 📖 AnkiHub Decks - AnkiHub Community

Let’s say I convert all my images to WebP with that add on, is there a way to convert back to the original higher quality PNG file afterwards? Like what if I’m not happy with the change in quality… is there no going back?

GIF uses old lossless compression, but supports few colors, although animation can be used to increase the number.
PNG uses lossless compression that compresses best the images with flat colors like diagrams and maps.
JPEG uses lossy compression that can compress photos so that when decompressing, the photo can look somewhat like the original, but a diagram would look visibly bad. If you compress a losslessly-compressed image with lossy compression, you can’t get the exact original image back.
WebP can use lossy or lossless compression, but it is relatively new, and some websites and software do not support it.

2 Likes

By the way, to observe size of your collection and individual notes the Note Size addon can be useful.

2 Likes

I think it is impossible to restore an image that has become low quality to high quality. Quality should be adjustable in Config.

  • Png animations will be static images if you use the webp add-on. (but png animations are rarely included in the deck.)

  • Webp works best if the image is large and not optimized. If the image is already small converting it to webp may not reduce the total size. (I tried converting a free deck of AnkingV11 to webp before but it didn’t reduce the size as much as I expected because of too many small images).

  • If you don’t have most of your decks learned yet, you may want to split the deck into several decks and store the decks you don’t want to learn yet on your local device. (sync will be easier)

  • Webp should display fine on desktop and AnkiMobile and AnkiDroid. AnkiWeb may be browser dependent, it is displayed fine in Chrome on my device.

1 Like

On my iPad, when I use compressimage(.io) to convert my PNG files to WebP with 90% image quality, I’m blown away with how much file size is reduced and I literally cannot tell the difference in quality. I just tried 5 images as a test and there was 90% size reduction (13.7 MB to 1.4 MB) without altering the physical size of the images. Afterwards, there is no perceptible difference in image quality… it almost seems too good to be true.

Anyways, I’m in no way trying to advertise this resource but it’s the only one I can easily use on my iPad to test WebP out. Now my question is, do you think if I use the add on you suggested and set the WebP conversion to 90% then it will have the same results? I don’t know enough about this stuff but I feel like it technically should. I just can’t test the add on right now since my desktop is getting worked on, so I’m currently limited to my iPad for now.

There are programs to recompress PNG images by trying different methods, in case they were just saved with low compression settings, like AdvanceCOMP and OptiPNG.
There is source code; I don’t know anything about getting Mac OS X binaries.

1 Like

Are those photo-like images saved from a video player or pasted from clipboard with “Paste clipboard images as PNG” enabled? Preferences - Anki Manual

I hope you made a backup of everything.

All of my images are iPad screenshots from clipboard with “Paste clipboard images as PNG” enabled. I’m starting to run out of space on my device with this method so that’s why I’m now trying to compress them, but I really don’t want to alter the overall image quality too much.

Webp should display fine on desktop and AnkiMobile and AnkiDroid. AnkiWeb may be browser dependent, it is displayed fine in Chrome on my device.

WebP can use lossy or lossless compression, but it is relatively new, and some websites and software do not support it.

Don’t worry about this

WebP: Widely available across major browsers
Since September 2020, this feature works across the latest devices and major browser versions
Global usage: 95.69% WebP image format | Can I use... Support tables for HTML5, CSS3, etc

AVIF: Newly available across major browsers
Since January 2024, this feature works across the latest devices and major browser versions
Global usage: 92.64% AVIF image format | Can I use... Support tables for HTML5, CSS3, etc

2 Likes

If you are comfortable with a little shell programming you could try imagemagick.

I frequently create cards with screenshots, and since I have a retina display the images are always twice as big as the need to be. What I do is:

  1. go into Anki’s media folder
  2. move all the images into another external folder
  3. open all the images in the Preview app (Mac, MS and Linux probably have something similar)
  4. make sure all the images are selected in the side bar
  5. change the size of the images using the tools menu
  6. save
  7. move the images back into the media folder

This reduces the size and/or the resolution of the images rather than compressing them, but maybe it’s still an option for you.

2 Likes