Skip to content

Document the compress_type save option for PNG - #10278

Merged
radarhere merged 2 commits into
python-pillow:mainfrom
qodelicious:docs-png-compress-type
Oct 22, 2026
Merged

radarhere merged 2 commits into
python-pillow:mainfrom
qodelicious:docs-png-compress-type

Conversation

@qodelicious

Copy link
Copy Markdown
Contributor

Changes proposed in this pull request:

I saved a gradient with each strategy to check they all work and that leaving it out gives the same file as Z_FILTERED. sphinx-lint is happy.

@radarhere

radarhere commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

the default is zlib.Z_FILTERED, which is what ZipEncode.c uses for PNG when it isn't set

This isn't quite correct. If the mode is P, it is Z_DEFAULT_STRATEGY.

"P": ("P", b"\x08", b"\x03"),

Pillow/src/encode.c

Lines 655 to 658 in 0c8cc31

if (rawmode == IMAGING_RAWMODE_P || rawmode == IMAGING_RAWMODE_PA) {
/* disable filtering */
((ZIPSTATE *)encoder->state.context)->mode = ZIP_PNG_PALETTE;
}

compress_type =
(context->mode == ZIP_PNG) ? Z_FILTERED : Z_DEFAULT_STRATEGY;

@radarhere
radarhere force-pushed the docs-png-compress-type branch from 40c52e6 to 674c3c8 Compare October 22, 2026 09:02
@radarhere
radarhere merged commit d4b99a3 into python-pillow:main Oct 22, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants