modify image and save with exif data

jwe.van.dijk at gmail.com jwe.van.dijk at gmail.com
Mon Dec 17 10:10:37 CET 2012


On Sunday, 16 December 2012 20:43:12 UTC+1, jwe.va... at gmail.com  wrote:
> I want to resize an image but retain the exif data
> 
> I now have:
> 
> import Image
> 
> 
> 
> img = Image.open('photo.jpg')
> 
> img.thumbnail((800, 800), Image.ANTIALIAS)
> 
> img.save('photo800.jpg', 'JPEG')
> 
> 
> 
> The saved image photo800.jpg has no exif info anymore.
> 
> I would so much like to have it retained in particular the exposure and gps data.
> 
> 
> 
> I use Python 2.7 with PIL 1.17 on Ubuntu 12.04
> 
> For exif reading/writing I use pyexiv2 0.3.2 but apparently you cannot add tags to an image that has none; only modifying existing ones seems to work.
> 
> 
> 
> Thanks for any helpful suggestions,
> 
> Janwillem

Thanks Vincent,
I tried that but without try-except. I should have done and with also a try except in your except it works. It appears that the failure is in a few Nikon tags that apparently can be read but not set.

Setting Exif.Nikon3.0x002d failed, <class 'pyexiv2.utils.NotifyingList'>
Setting Exif.Nikon3.0x009d failed, <type 'int'>
Setting Exif.Nikon3.ExposureTuning failed, <type 'str'>
Setting Exif.Nikon3.Preview failed, <type 'long'>

Not important so I am happy with your tip.
Janwillem



More information about the Python-list mailing list