How to use the exif.parse_datetime function in exif

To help you get started, we’ve selected a few exif examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github twpayne / igc2kmz / igc2kmz / photo.py View on Github external
def __init__(self, url, path=None):
        self.url = url
        components = urlparse.urlparse(self.url)
        self.name = os.path.splitext(os.path.basename(components.path))[0]
        if path:
            file = open(path)
        else:
            file = urllib2.urlopen(self.url) 
            if file.info().typeheader != 'image/jpeg':
                raise RuntimeError, '%s: not an image/jpeg' % self.url
        self.jpeg = exif.JPEG(file)
        if 'DateTimeOriginal' in self.jpeg.exif:
            self.dt = exif.parse_datetime(self.jpeg.exif['DateTimeOriginal'])
        elif 'DateTime' in self.jpeg.exif:
            self.dt = exif.parse_datetime(self.jpeg.exif['DateTime'])
        else:
            self.dt = datetime.datetime(2000, 1, 1)
        if 'GPSVersionID' in self.jpeg.exif:
            lat = exif.parse_angle(self.jpeg.exif['GPSLatitude'])
            if self.jpeg.exif['GPSLatitudeRef'] == 'S\0':
                lat = -lat
            lon = exif.parse_angle(self.jpeg.exif['GPSLongitude'])
            if self.jpeg.exif['GPSLongitudeRef'] == 'W\0':
                lon = -lon
            if 'GPSAltitude' in self.jpeg.exif:
                gps_altitude = self.jpeg.exif['GPSAltitude']
                ele = float(gps_altitude[0]) / gps_altitude[1]
                self.elevation_data = True
            else:

exif

Read and modify image EXIF metadata using Python.

MIT
Latest version published 2 years ago

Package Health Score

72 / 100
Full package analysis