擅长:python、mysql、java
<p>图像Exif信息可在本文档中找到:</p>
<p><a href="http://www.cipa.jp/std/documents/e/DC-008-2012_E.pdf" rel="nofollow noreferrer">http://www.cipa.jp/std/documents/e/DC-008-2012_E.pdf</a></p>
<p>使用piexif库构建exif信息并写入目标文件:(python)</p>
<p><strong>构建exif信息以保持源文件的方向,而源文件被windows读取以显示正确的方向。</strong></p>
<p><strong>来源:<a href="http://piexif.readthedocs.io/en/latest/functions.html?highlight=save" rel="nofollow noreferrer">http://piexif.readthedocs.io/en/latest/functions.html?highlight=save</a></strong></p>
<pre><code>zeroth_ifd = {piexif.ImageIFD.Orientation: image_orientation,
piexif.ImageIFD.ImageWidth: int(new_width),
piexif.ImageIFD.ImageLength: int(new_height),
piexif.ImageIFD.Software: u"piexif"
}
exif_dict = {"0th":zeroth_ifd}
exif_bytes = piexif.dump(exif_dict)
with open(dest, 'r+b') as f:
with Image.open(dest,'r') as image:
image.save(dest, "jpeg", exif=exif_bytes)
</code></pre>