Add function convert_to_srgb.

This commit is contained in:
voussoir 2023-06-24 23:59:12 -07:00
parent e0e12c0184
commit 6fe7e5e5a6

View file

@ -5,6 +5,7 @@ import exifread
import io
import PIL.ExifTags
import PIL.Image
import PIL.ImageCms
import re
from voussoirkit import pathclass
@ -40,6 +41,20 @@ def checkerboard_image(color_1, color_2, image_size, checker_size) -> PIL.Image:
offset = not offset
return image
def convert_to_srgb(image):
'''
Thank you Andriy Makukha
https://stackoverflow.com/a/50623824
'''
icc = image.info.get('icc_profile', '')
if icc:
image = PIL.ImageCms.profileToProfile(
image,
inputProfile=PIL.ImageCms.ImageCmsProfile(io.BytesIO(icc)),
outputProfile=PIL.ImageCms.createProfile('sRGB'),
)
return image
def fit_into_bounds(
image_width,
image_height,