Do not pad PNG palette when saving if bits is specified - #10029
Merged
Merged
Conversation
When saving a P mode image as PNG with an explicit bits argument, Pillow has always padded the PLTE (and tRNS) chunks with zeroes up to 2 ** bits entries. This adds an opt-in palette_padding=False option so only the actual palette entries are written, per issue #10028. Defaults to True, preserving existing behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Drop the palette_padding option and always trim the PLTE/tRNS chunks to the palette's actual size, matching the non-explicit-bits path, which has done this since #5330 (2021) with no compatibility issues. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
radarhere
force-pushed
the
png-palette-padding
branch
3 times, most recently
from
September 21, 2026 07:16
34a8327 to
54f6335
Compare
radarhere
approved these changes
Sep 21, 2026
radarhere
force-pushed
the
png-palette-padding
branch
from
September 21, 2026 07:19
54f6335 to
5833866
Compare
radarhere
force-pushed
the
png-palette-padding
branch
from
September 21, 2026 07:29
5833866 to
78e0777
Compare
radarhere
marked this pull request as ready for review
September 21, 2026 14:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #10028.
Adds an opt-inpalette_padding=FalsePNG save option so thePLTE/tRNSchunks aren't padded up to2 ** bitsentries whenbitsis explicitly specified.Defaults toTrue, preserving current behavior.