October 24, 2024
Chicago 12, Melborne City, USA
python

Suboptimal PNG and GIF compression using Pillow?


I’ve noticed that opening a GIF or PNG file in Pillow and then saving it unchanged can increase the file size, even when optimize=True is specified.

For example, the GIF at https://i.giantitp.com//comics/oots/oots0001.gif has size 109220 bytes, but when saved via Image.open("oots001.gif").save("oots001_copy.gif", optimize=True) the size increases to 121630 bytes.

Similarly, the PNG at https://i.giantitp.com//comics/oots/oots1000.png has size 1589401, but when saved via Image.open("oots1000.png").save("oots1000_copy.png", optimize=True) the size increases to 2136596 bytes (and without optimization it’s 2172818 bytes).

Is there any way to compress these files optimally using Pillow?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video