I change the exif on a jpeg using piexif to read and write exif data, which seems to work fine. The issue is when I read and write the jpeg, even tho I don't change the bytes, it saves the picture with different pixels and the picture that was read. I need it to be exactly the same pixels. I understand this is because jpeg is a lossy format, but the only way I've found around it is to save it as a png and then export it as a jpeg with Mac Preview, which is not good, because I have hundreds of pictures.
def adjust_img(path):
img = PIL.Image.open(path)
exif_dict = piexif.load(img.info['exif'])
new_exif = adjust_exif(exif_dict)
exif_bytes = piexif.dump(new_exif)
pc = path.split('/')
stem = '/'.join(pc[:-1])
img.save('%s/_%s' % (stem,pc[-1]), "JPEG", exif=exif_bytes, quality=95, optimize=False)
How can I preserve the picture and just alter the exif?
Yes EXIF data can be altered. You can change the fields in post with certain programs. You can also fake the date simply by changing the date and time of the camera before taking the picture, there's nothing that says a camera has to have the exact date and time.
While metadata can be useful, sometimes it can also be considered a security concern for many people. Thankfully, you cannot only edit metadata, but the operating system also lets you remove in bulk certain properties that might contain personal information, such as name, location, etc.
https://piexif.readthedocs.io/en/latest/functions.html
exif_dict = piexif.load(path)
new_exif = adjust_exif(exif_dict)
exif_bytes = piexif.dump(new_exif)
piexif.insert(exif_bytes, path)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With