ICC profiles #14
-
Please tell me, сan we work with ICC color profiles? I'm interested in adding a profile to image. If this is not possible, please help me understand the situation: image = exiv2.ImageFactory.open(rgb_target)
image.setExifData(exif_from_source_raw)
image.writeMetadata() This does only one good thing - it adds metadata from source_raw to rgb_target, but at the same time it destroys the existing ICC-profile. I understand that it replaces the old with the new. Is it possible to somehow combine existing ICC data and new other data? (e.g. image.setExifData(exif_from_source_raw + exif_from_rgb_target)) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 14 replies
-
The |
Beta Was this translation helpful? Give feedback.
-
Everything works fine: modification metadata, embedding icc (for Jpeg and Tiff). But the WebP format came as a surprise. Metadata is good. But when embedding an ICC profile, the file becomes unreadable. A check in the HEX editor showed that the EXIV2 does not put down the necessary marker "ICCP" WebP Container Specification. Everything is OK on the CLI version 0.27.7 of Windows 😕 I manually place the desired marker and the image comes to life. Of course, as long as the data is in RAM, I can patch the file. However, this behavior in relation to this format seems strange. Maybe there was an error somewhere or some factor was missed? Here is a slightly simplified code from my project regarding working with EXIV2. If you comment out the from io import BytesIO
from PIL import Image
import exiv2 # v0.15
color_space = None
# Initialize common ICC profiles (sRGB IEC61966-2.1 and Adobe RGB 1998) in buffer
with open("/tools/srgb.icc", "rb") as file_icc:
icc_data_srgb = file_icc.read()
with open("/tools/adobe_rgb_1998.icc", "rb") as file_icc:
icc_data_argb98 = file_icc.read()
input_file = "/Users/test/Desktop/0050-master-flat.tif"
img = Image.open(input_file)
img.thumbnail((900, 900), Image.Resampling.BICUBIC)
buffer_ = BytesIO()
# img.save(buffer_, format="JPEG", subsampling=1, progressive=1, optimize=1, quality=75)
img.save(buffer_, format="webp", method=6, quality=75)
image_ref_file = exiv2.ImageFactory.open(input_file)
image_ref_file.readMetadata()
exif_ref = image_ref_file.exifData()
i = exif_ref.begin()
end = exif_ref.end()
exif_custom = exiv2.ExifData()
while i != end:
if "ColorSpace" in i.key():
# 1 - sRGB, 2 - Adobe RGB 1998
if i.toString() == "1":
color_space = 1
elif i.toString() == "2":
color_space = 2
if i.key() in (
'Exif.Photo.ExposureTime',
'Exif.Photo.ISOSpeedRatings',
'Exif.Image.Make'
):
exif_custom[i.key()] = i.value()
next(i)
image = exiv2.ImageFactory.open(buffer_.getvalue())
image.setExifData(exif_custom)
# Embedd ICC profile
image.setIccProfile(exiv2.DataBuf(icc_data_srgb if color_space == 1 else icc_data_argb98))
image.writeMetadata()
io = image.io()
# with open("/Volumes/Disk/out/0050-master-flat.jpg", 'wb') as file:
# file.write(io.mmap())
with open("/Volumes/Disk/out/0050-master-flat.webp", 'wb') as file:
file.write(io.mmap())
io.munmap()
io.close() Tiff and profiles |
Beta Was this translation helpful? Give feedback.
That's a bug in the libexiv2 webp implementation: Exiv2/exiv2#2734
When I get libexiv2 0.28.1 (or later) properly working with python-exiv2 then it should be fixed.