Python:从图像中删除 Exif 信息 [英] Python: Remove Exif info from images

查看:47
本文介绍了Python:从图像中删除 Exif 信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了减小网站中要使用的图像的大小,我将质量降低到 80-85%.这在一定程度上减少了图像大小.

In order to reduce the size of images to be used in a website, I reduced the quality to 80-85%. This decreases the image size quite a bit, up to an extent.

为了在不影响质量的情况下进一步缩小尺寸,我的朋友指出来自相机的原始图像有很多称为 Exif 信息的元数据.由于不需要为网站中的图像保留此 Exif 信息,我们可以将其删除.这将进一步减少 3-10 kB 的大小.

To reduce the size further without compromising the quality, my friend pointed out that raw images from cameras have a lot of metadata called Exif info. Since there is no need to retain this Exif info for images in a website, we can remove it. This will further reduce the size by 3-10 kB.

但是我无法在我的 Python 代码中找到合适的库来执行此操作.浏览了相关问题,尝试了一些方法:

But I'm not able to find an appropriate library to do this in my Python code. I have browsed through related questions and tried out some of the methods:

原始图片:http://mdb.ibcdn.com/8snmhp4sjd75vdr27gbadolc003i.jpg

Original image: http://mdb.ibcdn.com/8snmhp4sjd75vdr27gbadolc003i.jpg

  1. Mogrify

/usr/local/bin/mogrify -strip filename

结果:http://s23.postimg.org/aeaw5x7ez/8snmhp4sj207g5snhp4sjdrc07g55gbadolc003i_mogrify.jpg一>这种方法将大小从 105 kB 减少到 99.6 kB,但也改变了颜色质量.

Result: http://s23.postimg.org/aeaw5x7ez/8snmhp4sjd75vdr27gbadolc003i_mogrify.jpg This method reduces the size from 105 kB to 99.6 kB, but also changed the color quality.

Exif 工具

exiftool -all= filename

结果:http://s22.postimg.org/aiq99o775/8snm5jpg0dlfc0.com一>这种方法将大小从 105 kB 减少到 72.7 kB,但也改变了颜色质量.

Result: http://s22.postimg.org/aiq99o775/8snmhp4sjd75vdr27gbadolc003i_exiftool.jpg This method reduces the size from 105 kB to 72.7 kB, but also changed the color quality.

谁能帮我删除所有额外的元数据而不改变图像的颜色、尺寸和其他属性?

Can anyone please help me remove all the extra metadata without changing the colours, dimensions, and other properties of an image?

推荐答案

您可以尝试使用 Python 图像库 (PIL),然后再次将其保存到不同的文件中.那应该删除元数据.

You can try loading the image with the Python Image Lirbary (PIL) and then save it again to a different file. That should remove the meta data.

这篇关于Python:从图像中删除 Exif 信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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