在Python中调整图像大小而不会丢失EXIF数据 [英] Resize image in Python without losing EXIF data

查看:620
本文介绍了在Python中调整图像大小而不会丢失EXIF数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Python调整jpg图像的大小,而不会丢失原始图像的EXIF数据(有关日期的元数据,相机型号等)。关于python和图像的所有谷歌搜索都指向我正在使用的PIL库,但似乎无法保留元数据。我到目前为止的代码(使用PIL)是这样的:

I need to resize jpg images with Python without losing the original image's EXIF data (metadata about date taken, camera model etc.). All google searches about python and images point to the PIL library which I'm currently using, but doesn't seem to be able to retain the metadata. The code I have so far (using PIL) is this:

img = Image.open('foo.jpg')
width,height = 800,600
if img.size[0] < img.size[1]:
    width,height = height,width

resized_img = img.resize((width, height), Image.ANTIALIAS) # best down-sizing filter
resized_img.save('foo-resized.jpg')

有什么想法吗?或者我可以使用的其他库?

Any ideas? Or other libraries that I could be using?

推荐答案

import jpeg
jpeg.setExif(jpeg.getExif('foo.jpg'), 'foo-resized.jpg') 

http://www.emilas.com/jpeg/

这篇关于在Python中调整图像大小而不会丢失EXIF数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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