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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…