Coder Social home page Coder Social logo

pexif's Introduction

Python EXIF parsing

pexif is a Python library for parsing and more importantly editing EXIF data in JPEG files.

This grew out of a need to add GPS tagged data to my images, Unfortunately the other libraries out there couldn't do updates and didn't seem easily architectured to be able to add such a thing. Ain't reusable software grand!

Apps

  • dump_exif.py: Output the EXIF file from a given file.
  • setgps.py: Set the GPS metadata on a file.
  • getgps.py: Get the GPS metadata from a file.
  • noop.py: This is a no-op on a jpeg file. Useful for testing images are preserved across operations using pexif. Note that the binary data will not be exact as pexif will compress unused space in the file, however running it on a file twice should end up with the same data.

Examples

  • hello.py: Add a simple description to a photo.

Status:

WARNING: This could destroy your images!! Backup your images before using.

Currently it parses files from my Canon without a problem, and is able to add a GPS tag without corrupting the rest of the image.

References

This work couldn't be done with the reference for the spec. In particular I worked to:

For the format of the Canon stuff I used:

For the format of FujiFILM make note:

Acknowledgments:

Nick Carter provided conker.jpg which is used for testing FUJIFILM exif data.

Nick Burch provided noexif.jpg which is used for testing inputs that don't have an existing EXIF segment. Nick burch also found an error in GeoTags on the S60.

Christopher Jones who inspired updating my examples to show how copying EXIF data from one jpeg to another.

Roland Klabunde who also found a bug in the GeoTag functionality.

Marcell Lengyel for adding better support for Canon g3 and FujiFilm z5fd.

Andrew Baumann for finding a bug in dealing with extended IFD sections, and supplying the timezone adjustment script.

pexif's People

Contributors

aphexcx avatar bennoleslie avatar deniscarriere avatar ed-holden avatar marcelometal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pexif's Issues

reading android image return: AttributeError: 'NoneType' object has no attribute 'size'

with this simple test program:

import pexif

# Modify  the exif in a file
img = pexif.JpegFile.fromFile("test.jpg")
img.exif.primary.ImageDescription =  "Hello world!"
img.writeFile("tmp1.jpg")
python test.py 
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    img = pexif.JpegFile.fromFile("test.jpg")
  File "/home/pat1/tmp/jpg/pexif.py", line 1002, in fromFile
    return JpegFile(f, filename=filename, mode=mode)
  File "/home/pat1/tmp/jpg/pexif.py", line 1065, in __init__
    attempt = segment_class(mark, input, data, self.mode)
  File "/home/pat1/tmp/jpg/pexif.py", line 858, in __init__
    DefaultSegment.__init__(self, marker, fd, data, mode)
  File "/home/pat1/tmp/jpg/pexif.py", line 151, in __init__
    self.parse_data(data)
  File "/home/pat1/tmp/jpg/pexif.py", line 902, in parse_data
    ifd = IfdTIFF(self.e, offset, self, self.mode, tiff_data)
  File "/home/pat1/tmp/jpg/pexif.py", line 418, in __init__
    actual_data = self.embedded_tags[tag][1](e, the_data, exif_file, self.mode, data)
  File "/home/pat1/tmp/jpg/pexif.py", line 412, in __init__
    exif_type_size(exif_type), components,
  File "/home/pat1/tmp/jpg/pexif.py", line 250, in exif_type_size
    return ExifType.lookup.get(exif_type).size
AttributeError: 'NoneType' object has no attribute 'size'

attached the sample image; sorry for the subject ;)

test

Support for thumbnail edit in ExifSegment

I am using pexif and wanna to modify image and adjust corresponding exif thumbnail.

As there is a comment in ExifSegment: "This module doesn't provide any useful functions for manipulating the thumbnail", I am wondering if you have any plan to do any support for the thumbnail editing/adjusting function? Thanks

SyntaxError: Missing parentheses in call to 'print'

I'm using Windows 10 with Python 3.5.1.

  1. Installed pexif 0.15 with pip
  2. Installation completed without problems
  3. Started a console window
  4. Executed import pexif
  5. Received the following exception:
Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pexif
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Balazs\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pexif.py", line 125
    print each,
             ^
SyntaxError: Missing parentheses in call to 'print'
>>>

Simplified Functions

Using simple functions would make it easier to remember and be more intuitive for a new comer.

Current

>>> jpeg = pexif.JpegFile.fromFile("foo.jpg")
>>> exif = jpeg.get_exif()
>>> jpeg.writeFile("new.jpg")

Proposed

>>> import pexif
>>> img = pexif.open('foo.jpg')
>>> exif = img.exif()
>>> img.write('new.jpg')

Major changes like this would require an entire overhaul of the code.

Add support for CR2 files

When I try to dump_exif.py in a RAW file saved with extension CR2 it throws the error:

dump_exif.py IMG_0002.CR2 
Error opening file: Error reading soi_marker. Got <II> should be <??>

It should display exif data just like a JPG file

Version 0.13 hosted externally causing error on pip

Hi bennoleslie,

I'm getting a error from newer versions of pip because almost all of pexif versions are in a external host, including the lastest version.

Updating pip and install pexif 0.13

pip install -U pip
pip install pexif==0.13

~/.pip/pip.log

  Analyzing links from page https://pypi.python.org/simple/pexif/
    Found link https://pypi.python.org/packages/source/p/pexif/pexif-0.2.tar.gz#md5=ff01000f9504ef478b9bf85c8649fcc4 (from https://pypi.python.org/simple/pexif/), version: 0.2
    Found link https://pypi.python.org/packages/source/p/pexif/pexif-0.3.tar.gz#md5=44ec19b168160524a4724f66b9dc6c78 (from https://pypi.python.org/simple/pexif/), version: 0.3
    Skipping link http://www.benno.id.au/code/pexif/ (from https://pypi.python.org/simple/pexif/); not a file
    Skipping http://www.benno.id.au/code/pexif/pexif-0.10.tar.gz (from https://pypi.python.org/simple/pexif/) because it is externally hosted.
    Skipping http://www.benno.id.au/code/pexif/pexif-0.11.tar.gz (from https://pypi.python.org/simple/pexif/) because it is externally hosted.
    Skipping http://www.benno.id.au/code/pexif/pexif-0.12.tar.gz (from https://pypi.python.org/simple/pexif/) because it is externally hosted.
    Skipping http://www.benno.id.au/code/pexif/pexif-0.13.tar.gz (from https://pypi.python.org/simple/pexif/) because it is externally hosted.
    Skipping http://www.benno.id.au/code/pexif/pexif-0.4.tar.gz (from https://pypi.python.org/simple/pexif/) because it is externally hosted.
    Skipping http://www.benno.id.au/code/pexif/pexif-0.5.tar.gz (from https://pypi.python.org/simple/pexif/) because it is externally hosted.
    Skipping http://www.benno.id.au/code/pexif/pexif-0.6.tar.gz (from https://pypi.python.org/simple/pexif/) because it is externally hosted.
    Skipping http://www.benno.id.au/code/pexif/pexif-0.8.tar.gz (from https://pypi.python.org/simple/pexif/) because it is externally hosted.
    Skipping http://www.benno.id.au/code/pexif/pexif-0.9.tar.gz (from https://pypi.python.org/simple/pexif/) because it is externally hosted.
  Ignoring link https://pypi.python.org/packages/source/p/pexif/pexif-0.2.tar.gz#md5=ff01000f9504ef478b9bf85c8649fcc4 (from https://pypi.python.org/simple/pexif/), version 0.2 doesn't match ==0.13
  Ignoring link https://pypi.python.org/packages/source/p/pexif/pexif-0.3.tar.gz#md5=44ec19b168160524a4724f66b9dc6c78 (from https://pypi.python.org/simple/pexif/), version 0.3 doesn't match ==0.13
  Could not find a version that satisfies the requirement pexif==0.13 (from versions: 0.2, 0.3)

Can you generate a version hosted on PyPi?
TY!

Integer overflow when setting coordinates with set_geo

Hello! I have the following error while writing image with new coordinates which have been set by set_geo function:

File "/usr/local/lib/python2.7/dist-packages/pexif.py", line 520, in getdata
actual_data += pack(e + t, *the_data[i].as_tuple())
error: 'i' format requires -2147483648 <= number <= 2147483647

I debug the code a little and saw that if we have here

secs = long(secs * JpegFile.SEC_DEN)

seconds more than 42,94967294 we have such an error.
So, why do you need to multiply seconds to JpegFile.SEC_DEN = 50000000 at all?

Thanks!

Release current master as a new version

Hi, first of all, thanks a lot for this library, it works really well.
Now, would it be possible for you to generate a new version and upload it to pypi? There are lots of fixes currently on master and not yet released on any version, ignoring unknown makers will be especially useful.

Set geo function improvements

Lat Lng to Floats

Lat Lng inputs can be tested for being floats in case their datatype is a string:

try:
   lat = float(lat)
except:
   pass

Add more Parameters

Would be nice to include more parameters like direction & elevation

  • Exif.GPSInfo.GPSImgDirection
  • Exif.GPSInfo.GPSImgDirectionRef
  • Exif.GPSInfo.GPSAltitude
  • Exif.GPSInfo.GPSAltitudeRef

Keep up the great work!

I'll send a fork once I have time to include these.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.