Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adding cICP chunk to PNG images #8703

Closed
spillerrec opened this issue Jan 18, 2025 · 1 comment · Fixed by #8704
Closed

Allow adding cICP chunk to PNG images #8703

spillerrec opened this issue Jan 18, 2025 · 1 comment · Fixed by #8704

Comments

@spillerrec
Copy link

What did you do?

Using PngInfo.add((b"cICP", bytes([9, 16, 0, 1])) to set the color space of a PNG to Rec. 2100.

What did you expect to happen?

The cICP chunk was added to the resulting PNG file.

What actually happened?

The cICP chunk was ignored as it is not in the list of allowed chunk names. This old gist shows a workaround which uses a temporary name to masquarade the chunk as a private chunk and then replaces putchunk to change the name back after the check:

https://gist.github.com/zhuowei/96b6e184bcf2de64433fbb86e15f7762

This chunk type is still only in a draft standard:

https://www.w3.org/TR/png-3/#cICP-chunk

But support is already implemented in a lot of applications:

https://w3c.github.io/png/Implementation_Report_3e/ (See section 2)

What are your OS, Python and Pillow versions?

  • OS: Windows 11
  • Python: 3.10.11
  • Pillow: 11.1.0
--------------------------------------------------------------------
Pillow 11.1.0
Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
--------------------------------------------------------------------
Python executable is F:\python\python.exe
System Python files loaded from F:\python
--------------------------------------------------------------------
Python Pillow modules loaded from F:\python\lib\site-packages\PIL
Binary Pillow modules loaded from F:\python\lib\site-packages\PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 11.1.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.3
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.5.0
--- JPEG support ok, compiled for libjpeg-turbo 3.1.0
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.3
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1.zlib-ng, compiled for zlib-ng 2.2.2
--- LIBTIFF support ok, loaded 4.6.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1, fribidi 1.0.16, harfbuzz 10.1.0
*** LIBIMAGEQUANT (Quantization method) support not installed
*** XCB (X protocol) support not installed
--------------------------------------------------------------------
import sys
from PIL import Image, PngImagePlugin

with Image.open(sys.argv[1]) as img:
    pnginfo = PngImagePlugin.PngInfo()
    pnginfo.add(b"cICP", bytes([9, 16, 0, 1]))
    img.save(sys.argv[2], pnginfo=pnginfo)
@radarhere
Copy link
Member

I've created #8704

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants