Skip to content

Do not pad PNG palette when saving if bits is specified - #10029

Merged
radarhere merged 4 commits into
mainfrom
png-palette-padding
Sep 21, 2026
Merged

radarhere merged 4 commits into
mainfrom
png-palette-padding

Conversation

@aclark4life

@aclark4life aclark4life commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Fixes #10028. Adds an opt-in palette_padding=False PNG save option so the PLTE/tRNS chunks aren't padded up to 2 ** bits entries when bits is explicitly specified. Defaults to True, preserving current behavior.

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>
aclark4life and others added 2 commits September 20, 2026 15:43
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
radarhere force-pushed the png-palette-padding branch 3 times, most recently from 34a8327 to 54f6335 Compare September 21, 2026 07:16
@radarhere radarhere changed the title Add palette_padding option to skip padding PLTE/tRNS chunks Do not pad PNG palette when saving when bits is specified Sep 21, 2026
@radarhere radarhere changed the title Do not pad PNG palette when saving when bits is specified Do not pad PNG palette when saving if bits is specified Sep 21, 2026
@radarhere
radarhere marked this pull request as ready for review September 21, 2026 14:05
@radarhere radarhere added the 🤖-assisted AI-assisted label Sep 21, 2026
@radarhere
radarhere merged commit 0449619 into main Sep 21, 2026
116 of 118 checks passed
@radarhere
radarhere deleted the png-palette-padding branch September 21, 2026 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖-assisted AI-assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid padding indexed PNG palettes

2 participants