Skip to content

Instantly share code, notes, and snippets.

Created September 5, 2022 05:16
What would you like to do?
Adds a cICP tag to PNG files
import sys
from PIL import Image, PngImagePlugin
# adds a cICP chunk to PNG files to specify color gamut and HDR brightness.
# This example uses the sample BT2020 + PQ cICP chunk from
# Requires Pillow >8.0.0. See
# View the resulting PNG in an app that supports cICP chunks, such as Chrome 105+
# (
# For more information about CICP, see
def putchunk_hook(fp, cid, *data):
if cid == b"haxx":
cid = b"cICP"
return PngImagePlugin.putchunk(fp, cid, *data)
with[1]) as im:
pnginfo = PngImagePlugin.PngInfo()
pnginfo.add(b"haxx", bytes([9, 16, 0, 1]))
im.encoderinfo = {"pnginfo": pnginfo}
with open(sys.argv[2], "wb") as outfile:
PngImagePlugin._save(im, outfile, sys.argv[2], chunk=putchunk_hook)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment