Skip to content

Preserve info when using ImageOps to expand or pad images - #10726

Merged
radarhere merged 2 commits into
python-pillow:mainfrom
Riken0321:fix/preserve-icc-when-padding
Dec 4, 2026
Merged

radarhere merged 2 commits into
python-pillow:mainfrom
Riken0321:fix/preserve-icc-when-padding

Conversation

@Riken0321

Copy link
Copy Markdown
Contributor

I found this while checking whether a color-managed PNG survives letterbox padding before image-model preprocessing. ImageOps.pad and ImageOps.expand paste the source into a new canvas and drop the ICC profile. The saved PNG consequently loses the source color space.

  • Copy the ICC profile to the padded canvas. Padding does not convert pixel values, so the original profile is still needed to interpret them.
  • Add regressions for both operations using Pillow's existing ICC fixture. Both check that the exact profile survives a PNG save and reopen.
  • Document the behavior in the 13.1.0 release notes.

On Windows, selftest.py passed 59 checks, and Tests/test_imageops.py plus Tests/test_file_png.py returned 159 passed and 1 skipped. I ran these with the checked-out Python sources and the 13.1.0.dev0 native libraries from the upstream Windows AMD64 build. Both new regression cases failed with the upstream ImageOps source restored.

Developed and tested with OpenAI Codex.

If you have questions about this change, you can reach me at huangriken@gmail.com.

@radarhere radarhere added the 🤖-assisted AI-assisted label Dec 4, 2026
@radarhere

Copy link
Copy Markdown
Member

After this on top of #9995, I've pushed a commit to copy all of info.

@radarhere radarhere changed the title Preserve ICC color profiles when padding images Preserve info when using ImageOps to expand or pad images Dec 4, 2026
@radarhere
radarhere merged commit 6b0de44 into python-pillow:main Dec 4, 2026
67 of 74 checks passed
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.

2 participants