3

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

Community
  • 1
  • 1
krivar
  • 312
  • 1
  • 3
  • 15
  • What happens if you run optipng or pngcrush on the 17kb PNG file? Do either of those succeed in reducing it? – rmunn Jun 08 '13 at 18:26
  • @rmunn optipng took it from 17.9kb to 8.6kb (it's 320x200) while the original (640x400) is 6.4kb. Should I still check with pngcrush too? – krivar Jun 08 '13 at 18:59

1 Answers1

3

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.

korylprince
  • 2,756
  • 1
  • 15
  • 25