modify image and save with exif data

Discussion in 'Python' started by jwe.van.dijk@gmail.com, Dec 16, 2012.

  1. Guest

    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
     
    , Dec 16, 2012
    #1
    1. Advertising

  2. Le 16/12/12 20:43, 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>
     
    Vincent Vande Vyvre, Dec 17, 2012
    #2
    1. Advertising

  3. Guest

    On Sunday, 16 December 2012 20:43:12 UTC+1, 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
     
    , Dec 17, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim
    Replies:
    3
    Views:
    7,242
    Paul Bilnoski
    Aug 4, 2005
  2. Paul Archer
    Replies:
    2
    Views:
    391
    Paul Archer
    Apr 17, 2009
  3. David Dyer-Bennet

    Image::EXIF troubles

    David Dyer-Bennet, Nov 14, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    126
    Martin Herrmann
    Nov 15, 2004
  4. David Dyer-Bennet
    Replies:
    1
    Views:
    151
    Martin Herrmann
    Nov 15, 2004
  5. Marcin Owsiany

    Proposal: Image::EXIF::DateTime::Parser

    Marcin Owsiany, May 8, 2009, in forum: Perl Misc
    Replies:
    2
    Views:
    138
    Marcin Owsiany
    May 11, 2009
Loading...

Share This Page