Skip to main content

Exiv2 wrapper for Python >= 3.4 on Windows

Project description

Low-level wrapper for exiv2 for python >= 3.3 that pip-installs on Windows.

  • only works on Windows.

  • only supports Iptc for now. Exif and Xmp are on their way.

  • straight-up exposure of the C++ methods. Feel free to write more pythonic classes on top.

How do I set it up?

  • pip install exiv2

Example

import exiv2
from PIL import Image

def example(path):
    ''' Open an image on disk and get one piece of IPC data.
    '''
    with open(path, "rb") as f:
        imdata = f.read()
    im = exiv2.ImageFactory.open(imdata)
    im.readMetadata()
    ipc_data = im.iptcData()
    # exiv2 method "toString()" actually returns bytes, so we have to decode it
    info = ipc_data[b'Iptc.Application2.Caption'].toString().decode('utf-8')
    return info

def example2():
    ''' Open image, change IPTC data and save the image.
    '''
    image = exiv2.ImageFactory.open(r"c:\test\test.jpg")
    image.readMetadata()
    ipc_data = image.iptcData()
    for datum in ipc_data:
        print(datum.key(), datum.value().toString())
    ipc_data[b'Iptc.Application2.Subject'] = b'subject'
    image.writeMetadata()

def example3():
    ''' Open image in memory
    '''
    with open(r"c:\test\test.jpg", "rb") as f:
        imdata = f.read()
    im = exiv2.ImageFactory.open(imdata)
    im.readMetadata()

    new_iptc_data = exiv2.IptcData()
    new_iptc_data[b"Iptc.Application2.Caption"] = b'Hi Mom!'
    im.setIptcData(new_iptc_data)
    im.clearExifData()
    im.clearXmpData()
    im.writeMetadata()

    io = im.io()
    size = io.size()
    buffer = io.read(size)
    with open(r"c:\test\out.jpg", "wb") as f:
        f.write(buffer)

if __name__ == '__main__':
    example1()
    example2()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

exiv2-0.3.1-cp38-cp38-win_amd64.whl (985.1 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

exiv2-0.3.1-cp38-cp38-win32.whl (852.9 kB view hashes)

Uploaded CPython 3.8 Windows x86

exiv2-0.3.1-cp37-cp37m-win_amd64.whl (984.9 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

exiv2-0.3.1-cp37-cp37m-win32.whl (852.6 kB view hashes)

Uploaded CPython 3.7m Windows x86

exiv2-0.3.1-cp36-cp36m-win_amd64.whl (986.4 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

exiv2-0.3.1-cp36-cp36m-win32.whl (854.1 kB view hashes)

Uploaded CPython 3.6m Windows x86

exiv2-0.3.1-cp35-cp35m-win_amd64.whl (986.4 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

exiv2-0.3.1-cp35-cp35m-win32.whl (854.1 kB view hashes)

Uploaded CPython 3.5m Windows x86

exiv2-0.3.1-cp34-cp34m-win_amd64.whl (986.4 kB view hashes)

Uploaded CPython 3.4m Windows x86-64

exiv2-0.3.1-cp34-cp34m-win32.whl (854.1 kB view hashes)

Uploaded CPython 3.4m Windows x86

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page