Avoid padding indexed PNG palettes

Open
#10,028 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python

Research direction

Start by tracing Pillow’s PNG save path for the bits=4 case and the code that emits the PLTE chunk. Check existing PNG save tests, then verify that an opt-out produces a five-entry palette while the default remains padded and existing reads continue to work.

Written by the indexing model from the issue text.

Description

Hi.

Just a small feature request. Kind of niche use case so let me know if this is out-of-scope for Pillow.

Basically I'd like to save a PNG with bits=4 but with exactly 5 entries in the palette array. Currently, Pillow writes a 16-entry PLTE chunk regardless of the actual number of palette entries.

Could we imagine a small option such as palette_padding=False (default to True for retro-compatibility) to disable padding?

Note that this is permitted by the PNG specs and that Pillow reads these image well.

Dominant language
Python
Stars
13.8k
Forks
2.5k
Avg merge
2d 7h
Merged PRs (30d)
91

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python-pillow/Pillow

All issues in python-pillow/Pillow

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.