[英]Inserting icc color profile into image using Pillow ImageCMS
I am trying to insert an ICC color profile into an image.我正在尝试将 ICC 颜色配置文件插入到图像中。 Using code from this post as an example my code looks like this:以这篇文章中的代码为例,我的代码如下所示:
from PIL import Image, ImageCms
# Read image
img = Image.open(IMG_PATH)
# Read profile
profile = ImageCms.getOpenProfile(PROFILE_PATH)
# Save image with profile
img.save(OUT_IMG_PATH, icc_profile=profile)
I get the following error我收到以下错误
Traceback (most recent call last):
File "/home/----/Documents/code_projects/hfss-misc/icc_profiles/insert_icc_profile_into_image.py", line 17, in <module>
img.save(OUT_IMG_PATH, icc_profile=srgb_profile)
File "/home/----/.virtualenvs/color-correction/lib/python3.6/site-packages/PIL/Image.py", line 2102, in save
save_handler(self, fp, filename)
File "/home/----/.virtualenvs/color-correction/lib/python3.6/site-packages/PIL/JpegImagePlugin.py", line 706, in _save
markers.append(icc_profile[:MAX_DATA_BYTES_IN_MARKER])
TypeError: 'PIL._imagingcms.CmsProfile' object is not subscriptable
I thought that there might be a problem with my ICC profile so I tried to use one generated by Pillow.我认为我的 ICC 配置文件可能有问题,所以我尝试使用 Pillow 生成的配置文件。
from PIL import Image, ImageCms
# Read image
img = Image.open(IMG_PATH)
# Creating sRGB profile
profile = ImageCms.createProfile("sRGB")
# Save image with profile
img.save(OUT_IMG_PATH, icc_profile=profile)
I still get the same error, however.但是,我仍然遇到同样的错误。
Does anyone know what the cause for this error is?有谁知道这个错误的原因是什么?
My system environment is as follows:我的系统环境如下:
The answer from github at ( https://github.com/python-pillow/Pillow/issues/4464 ) was to use profile.to_bytes()
:来自 github ( https://github.com/python-pillow/Pillow/issues/4464 ) 的答案是使用profile.to_bytes()
:
img.save(OUT_IMG_PATH, icc_profile=profile.tobytes())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.