更改JPEG上的EXIF数据而无需更改图片 [英] Change EXIF data on JPEG without altering picture

查看:83
本文介绍了更改JPEG上的EXIF数据而无需更改图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用piexif更改jpeg上的exif以读取和写入exif数据,这似乎很好用.问题是当我读写jpeg时,即使不更改字节,它也会保存具有不同像素的图片和读取的图片.我需要它是完全相同的像素.我了解这是因为jpeg是有损格式,但是我发现它的唯一方法是将其保存为png,然后使用Mac Preview将其导出为jpeg,这不好,因为我有数百张图片.

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)

如何保存图片并仅更改exif?

How can I preserve the picture and just alter the exif?

推荐答案

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)

这篇关于更改JPEG上的EXIF数据而无需更改图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆