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

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

问题描述

我需要在不丢失原始图像的 EXIF 数据(有关拍摄日期、相机型号等的元数据)的情况下使用 Python 调整 jpg 图像的大小.所有关于 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天全站免登陆