What does optimize do? Will it change the image palette?
#9866
Replies: 2 comments 2 replies
|
The 'filter selection' mentioned in the previous comment is not applied to P mode images. Lines 653 to 656 in c8c74c8 So for a P mode image, all Pillow/src/libImaging/ZipEncode.c Lines 81 to 82 in c8c74c8 https://docs.python.org/3/library/zlib.html#zlib.Z_BEST_COMPRESSION
So I don't think the Python documentation gives much more detail about the exact nature of the compression. Given that, I'm not convinced that our description is worse. You're asking questions about changing the mode or the palette. I'm not sure how best to clarify what we AREN'T doing. Would you be interested in suggesting a description? |
|
Sure! Let's compare the terms across different contexts: On Pillow, There are several PNG optimization tools, such as OptiPNG, ImageOptim, OxiPNG, ZopfliPNG, Trimage, and so many others. Many of them will convert the image mode RGBA→RGB→P if such conversion remains lossless. Part of that process includes reducing the palette size. Some of these tools even have the "optim" or variations of the term "optimize" in their name. Thus, it's fair to expect that Pillow will do similar conversions when That said, people would infer similar kinds of lossless image transformations/conversions in order to "optimize" the PNG for size. But apparently this isn't the case, or isn't always the case. I'm confused, or unsure. And that's why I'm asking for a more descriptive description, actually telling us what extra steps (beyond zlib compression level 9) are done. (In fact, the current Let's look at this another way. After reading the docs, I wish to be able to answer these questions myself:
Right now, with the current wording in the official docs, I'm afraid I'm unable to give an answer to these questions. And that's why I've started this thread here. And, like I mentioned, the GIF description is more concrete and more descriptive about the behavior of that option. |
Uh oh!
There was an error while loading. Please reload this page.
I was reading the docs on gif-saving and png-saving and jpeg-saving. I feel like the description for the PNG
optimizeis very vague and not useful enough.optimize=False. Or, for animated GIFs, I'll likely wantoptimize=True. This is helpful.Let me explain why this is too vague:
Well, that can mean completely different behaviors:
RGBAbut has no transparency, we could optimize it by converting toRGB. If the total amount of colors is up to 256, we could optimize it by converting toP.What is this extra processing? Changing zlib compression parameters? What does it mean, exactly?
After reading that short description in the docs, and after taking a quick look at the source-code, I'm still not sure what
optimizedoes.Can someone please make a PR improving the docs?
In my specific case, of course I want the final PNG file to be as small as possible, but I need to preserve the original palette. Unfortunately, I cannot know for sure how to achieve it just by reading the docs; instead I have to do some trial-and-error myself to understand the behavior of those
save()options.All reactions