Skip to content

ICC Profile not saved for TIF files #5225

@Crubert-digit

Description

@Crubert-digit

When loading an image from an array(image opened with cv2, skimage, etc.) and then saving it in .tif format, the icc_profile is not saved. For example:

import cv2
from PIL import Image, ImageCms

profile = ImageCms.getOpenProfile("AdobeRGB.icm")

img_cv2 = cv2.imread("original.png")
img_pil = Image.fromarray(cv2.cvtColor(img_cv2, cv2.COLOR_BGR2RGB))
img_pil.save("result_cv2_to_pil_tif.tif", icc_profile=profile.tobytes())

However, when doing the same for a ".png" file the icc_profile is saved

img_pil.save("result_cv2_to_pil_tif.tif", icc_profile=profile.tobytes())

I solved it adding the icc_profile to the info attribute prior saving the image:

img_pil.info['icc_profile'] = profile.tobytes()
img_pil.save("result_cv2_to_pil_tif.tif")

It seems a bug in the save method when the file format is .tif, as it not considers adding the icc_profile to the output image if it was not previously in the info attribute.

I haven't tested it with other file formats.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions