krivar
krivar

Reputation: 402

PIL png resize to smaller resolution makes file size bigger

I'm resizing .png files with python's PIL. For some reason the file size is 3x times bigger than the original, even though I the resolution got reduced. So how do I save the file correctly?

Test1: png(6kb, 200x200) >> png(17kb, 100x100) <-- the one that concerns me
Test2: png(6.7mb, 3600x2025) >> png(7.0mb, 3555x2000)
Test3: png(6.7mb, 3600x2025) >> png(0.1mb, 355x200)

img = Image.open(file_path)
img = img.resize((100, 100), Image.ANTIALIAS)
img.save(file_path, optimize=True)

Current conclusion: It seems there is no big difference with large PNG's so I can move on with my program. Though it is still silly that the size increases.

The topic has almost been talked about:
How to reduce the image file size using PIL
how to reduce png image filesize in PIL

Upvotes: 5

Views: 2603

Answers (1)

korylprince
korylprince

Reputation: 3009

Antialiasing can increase the image size. Consider an image with only black or white pixels. This would be easy to compress to a very small size. But say you downsized the image with antialias. Now all of a sudden you have a lot more colors.

Even though it looks smaller, it actually takes more information to store.

This becomes much more apparent on very small images where ratios between the two are much larger.

Upvotes: 4

Related Questions