Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34945 > unrolled thread
| Started by | jwe.van.dijk@gmail.com |
|---|---|
| First post | 2012-12-16 11:43 -0800 |
| Last post | 2012-12-17 01:10 -0800 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
modify image and save with exif data jwe.van.dijk@gmail.com - 2012-12-16 11:43 -0800
Re: modify image and save with exif data Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2012-12-17 07:39 +0100
Re: modify image and save with exif data jwe.van.dijk@gmail.com - 2012-12-17 01:10 -0800
| From | jwe.van.dijk@gmail.com |
|---|---|
| Date | 2012-12-16 11:43 -0800 |
| Subject | modify image and save with exif data |
| Message-ID | <31bba35e-53e7-4a75-8ac8-ea10f4a8b4b8@googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | Vincent Vande Vyvre <vincent.vandevyvre@swing.be> |
|---|---|
| Date | 2012-12-17 07:39 +0100 |
| Message-ID | <mailman.946.1355726830.29569.python-list@python.org> |
| In reply to | #34945 |
Le 16/12/12 20:43, jwe.van.dijk@gmail.com a écrit :
> 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
Hi,
If a tag is not already set you can create it with pyexiv2.
Example:
----------------------------------------------------------------------
self.data = pyexiv2.ImageMetadata(img.jpg)
self.data.read()
tag = "Exif.Image.ImageWidth"
try:
self.data[tag].value = sizes[0]
except:
self.data[tag] = pyexiv2.ExifTag(tag, sizes[0])
-----------------------------------------------------------------------
A more complete example:
http://bazaar.launchpad.net/~vincent-vandevyvre/oqapy/serie-1.0/view/head:/oqapy-1.0/metadata.py
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
[toc] | [prev] | [next] | [standalone]
| From | jwe.van.dijk@gmail.com |
|---|---|
| Date | 2012-12-17 01:10 -0800 |
| Message-ID | <23491bb8-7ded-4fae-8303-7109731b9639@googlegroups.com> |
| In reply to | #34945 |
On Sunday, 16 December 2012 20:43:12 UTC+1, jwe.va...@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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web