How to get ColorSpace attribute from Exif
Hello, I want to get colorSpace from image exif,my code is below:
from PIL import Image
current_image = Image.open("1.jpg")
exifs = current_image.info.get("exif") # bytes data
but the exifs is the bytes data, i don't know how to decode it, can you help me? Thanks very much!
Instead of using the "exif" part of the info dictionary, you can use getexif(). Within that data, you will want to get the EXIF IFD, pointed to by the EXIF IFD tag, and then get the ColorSpace tag.
from PIL import Image
current_image = Image.open("rgb.jpg")
exif = current_image.getexif().get_ifd(34665)
print(exif[40961])
https://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif/colorspace.html
Normally sRGB (=1) is used to define the color space based on the PC monitor conditions and environment. If a color space other than sRGB is used, Uncalibrated (=65535) is set. Image data recorded as Uncalibrated can be treated as sRGB when it is converted to Flashpix.
What is 34665?
The EXIF IFD tag. See the "Code" value at https://www.awaresystems.be/imaging/tiff/tifftags/exififd.html
Within the getexif(), there are a few sections, IFDs. There is EXIF, GPS and Interoperability. We have limited support for reading Makernote data.
If a image without icc profile, how to embed icc file to the image?
srgb_profile = ImageCms.createProfile("sRGB")
new_image = ImageCms.profileToProfile(current_image, None, srgb_profile, 0, "RGB") # this line error
I want to use the new_image to crop and resize action, finally to save as jpg file with srgb icc file.
Now i have a question, first to transform profile then do crop and resize action,then save as jpg file with icc profile or first do crop and resize action, no matter the profile, finally save as icc profile image?
Thank you for your reply.
Your question is no longer about EXIF data. It would be good to either create a new issue, or continue this in #6467.
It shouldn't matter at what point in the process you crop, as that doesn't affect pixel values.
Regarding an image without "icc_profile" in the info dictionary, https://stackoverflow.com/questions/50641637/identify-colour-space-of-any-image-if-icc-profile-is-empty-pil appears helpful.
You've also asked whether it is better to apply an ICC profile or to resize the image first. I would think it is better to resize first, as the resize operation may change the colors in a way that reduces the effectiveness of the ICC profile.
@julin69 has that answered your questions?
Closing this issue as no feedback has been received.