如何在python中修改EXIF数据 [英] How to modify EXIF data in python

查看:576
本文介绍了如何在python中修改EXIF数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编辑/修改python 2.7中的现有元数据.更具体而言,我在我的月历中有GPS坐标,但是海拔字段不正确.有办法改变吗?

I am trying to edit/modify existing metadata within python 2.7. More specifically I have GPS coordinates in a my metedata, however the altitude field is incorrect. Is there a way of changing this?

我看过PIL piexif pyexif,但是我似乎找不到修改现有字段的方法.

I have had a look at PIL piexif pyexif, but I cannot seem to find a way to modify existing fields.

有人设法做到这一点吗?听起来很简单,但我似乎无法解决.

Has anyone managed to do this? It sounds like it would be very simple, but I can't seem to work it out.

欢呼 戴夫

推荐答案

import piexif
from PIL import Image

img = Image.open(fname)
exif_dict = piexif.load(img.info['exif'])

altitude = exif_dict['GPS'][piexif.GPSIFD.GPSAltitude]
print(altitude)

(550,1)%某些值以小数格式保存.这意味着550m(51,2)将为25.5m.

(550, 1) % some values are saved in a fractional format. This means 550m, (51, 2) would be 25,5m.

exif_dict['GPS'][piexif.GPSIFD.GPSAltitude] = (140, 1)

这会将高度设置为140m

This sets the altitude to 140m

exif_bytes = piexif.dump(exif_dict)
img.save('_%s' % fname, "jpeg", exif=exif_bytes)

这篇关于如何在python中修改EXIF数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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