Add function convert_to_srgb.
This commit is contained in:
parent
e0e12c0184
commit
6fe7e5e5a6
1 changed files with 15 additions and 0 deletions
|
@ -5,6 +5,7 @@ import exifread
|
||||||
import io
|
import io
|
||||||
import PIL.ExifTags
|
import PIL.ExifTags
|
||||||
import PIL.Image
|
import PIL.Image
|
||||||
|
import PIL.ImageCms
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from voussoirkit import pathclass
|
from voussoirkit import pathclass
|
||||||
|
@ -40,6 +41,20 @@ def checkerboard_image(color_1, color_2, image_size, checker_size) -> PIL.Image:
|
||||||
offset = not offset
|
offset = not offset
|
||||||
return image
|
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(
|
def fit_into_bounds(
|
||||||
image_width,
|
image_width,
|
||||||
image_height,
|
image_height,
|
||||||
|
|
Loading…
Reference in a new issue