-
Hello, I'm completely new to Python / Pillow, sorry if my question isn't appropriate. The situation is:
with Image.open(imageFilePath) as image:
imgExif = image.getexif()
imgExif[0x0132] = '2022:10:05 17:00:30' # DateTime
imgExif[0x9003] = '2022:10:05 17:00:30' # DateTimeOriginal
imgExif[0x9004] = '2022:10:05 17:00:30' # DateTimeDigitized
image.save(outputImagePath, exif=imgExif.tobytes())
I've looked a bit into the tobytes() function in the Image.py file. I've noticed that, when any of these (0x8825 (decimal: 34853) = GPS Tag pointer, 0x8769 (decimal: 34665) = Exif Tag pointer, 0x8225) tags exists, then the EXIF is read again from the image file and added to ifd return value
I suppose, when it is converted to bytes, it overrides the values set previously. Please let me know if am I doing something wrong, is this intended? Have a great day, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I feel like you're halfway to figuring out the solution from the code. In terms of the specification, the problem is that while DateTime is a top-level tag, DateTimeOriginal and DateTimeDigitized are not. See https://www.awaresystems.be/imaging/tiff/tifftags/exififd.html, or look at the Group column of https://exiftool.org/TagNames/EXIF.html. It's not that your values are being overwritten as such. It's that you are setting them in the wrong place. The following code should save those values correctly. from PIL import Image
with Image.open(imageFilePath) as image:
imgExif = image.getexif()
imgExif[0x0132] = '2022:10:05 17:00:30' # DateTime
exif_ifd = imgExif.get_ifd(0x8769)
exif_ifd[0x9003] = '2022:10:05 17:00:30' # DateTimeOriginal
exif_ifd[0x9004] = '2022:10:05 17:00:30' # DateTimeDigitized
imgExif[0x8769] = exif_ifd
image.save(outputImagePath, exif=imgExif.tobytes()) |
Beta Was this translation helpful? Give feedback.
I feel like you're halfway to figuring out the solution from the code.
In terms of the specification, the problem is that while DateTime is a top-level tag, DateTimeOriginal and DateTimeDigitized are not. See https://www.awaresystems.be/imaging/tiff/tifftags/exififd.html, or look at the Group column of https://exiftool.org/TagNames/EXIF.html.
It's not that your values are being overwritten as such. It's that you are setting them in the wrong place.
The following code should save those values correctly.