How to use exif - 10 common examples

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 albertz / helpers / rename-pics.py View on Github external
def dump_exif(f):
    print("File", f, ":")
    try:
        info = exif.getexif(f)
    except exif.ExifException as e:
        print("  Error:", e)
    else:
        for k in sorted([k for k in info if isinstance(k, str)]) + sorted([k for k in info if not isinstance(k, str)]):
            print(" ", k, ":", user_repr(info[k]))
    print("  file creation time:", file_time_creation(f))
github albertz / helpers / rename-pics.py View on Github external
def iminfo(f):
    try:
        info = cleanup_exif_tags(exif.getexif(f))
    except exif.ExifException:
        info = {}
    if "DateTimeOriginal" in info:
        info["DateTime"] = info["DateTimeOriginal"]
    if "DateTime" not in info:
        info["DateTime"] = file_time_creation(f)
    return info
github freevo / freevo1 / iview.py View on Github external
def drawosd(self):

        if not self.osd: return
        
        f = open(self.filename, 'r')
        tags = exif.process_file(f)

        # Make the background darker for the OSD info
        osd.drawbox(0, osd.height - 110, osd.width, osd.height, width=-1,
                    color=((60 << 24) | osd.COL_BLACK))
        
        pos = 50

        if tags.has_key('Image DateTime') and \
		tags.has_key('EXIF ExifImageWidth') and tags.has_key('EXIF ExifImageLength'):
            osd.drawstring('%s (%s x %s) @ %s' % \
		(os.path.basename(self.filename), 
		 tags['EXIF ExifImageWidth'], tags['EXIF ExifImageLength'], \
		 tags['Image DateTime']), \
			 20, osd.height - pos, fgcolor=osd.COL_ORANGE)
	else:
            osd.drawstring('%s' % (os.path.basename(self.filename)), \
github gilesknap / gphotos-sync / gphotos / LocalFilesMedia.py View on Github external
def get_exif(self):
        try:
            with open(str(self.relative_folder / self.filename),
                      'rb') as image_file:
                self.__exif = exif.Image(image_file)
            self.got_meta = True
        except (IOError, AssertionError):
            self.got_meta = False
github twpayne / igc2kmz / igc2kmz / photo.py View on Github external
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:
                ele = 0
                self.elevation_data = False
            self.coord = Coord.deg(lat, lon, ele)
        else:
            self.coord = None
            self.elevation_data = None
github twpayne / igc2kmz / igc2kmz / photo.py View on Github external
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:
                ele = 0
                self.elevation_data = False
            self.coord = Coord.deg(lat, lon, ele)
        else:
            self.coord = None
            self.elevation_data = None
        if 'UserComment' in self.jpeg.exif:
            user_comment = self.jpeg.exif['UserComment']
            self.description = exif.parse_usercomment(user_comment)
github straup / filtr / utils / jpeg / olympus.py View on Github external
},
	0x201: { 'JPEGQuality': { 
				1:"SQ",
				2:"HQ",
				3:"SHQ"
            }
        },
	0x202: { 'Macro': {
				0:"Normal",
				1:"Macro"
	        }
        }
    }


class MakerNotes(InterpretedMakerNotes):
    def __init__(self, exif):
        super(MakerNotes, self).__init__(exif)

        for tag in olympus_map.keys():
            t = self._raw.get(tag)
            el, val = olympus_map[tag].items()[0]
            if val=={}:
                val = t.value
            else:
                val = val.get(t.value, "uknown: %s" % t.value)
            setattr(self.__class__, el, property(fget = lambda s, v=val: v))   #make it read only
github straup / filtr / utils / jpeg / canon.py View on Github external
0:"Auto",
				1:"Sunny",
				2:"Cloudy",
				3:"Tungsten",
				4:"Flourescent",
				5:"Flash",
				6:"Custom"},
			'SequenceNumber': {'mindex':9},                     #9
			'AFPointUsed': {'mindex':14},                     #14
			'FlashBias': { 'mindex':15,                  #15
				'.':"EV"},
			'SubjectDistance': {'mindex':19},                     #19
        }
        }

class MakerNotes(InterpretedMakerNotes):
    def __init__(self, exif):
        super(MakerNotes, self).__init__(exif)

        for tag in canon_map.keys():
            t = self._raw.get(tag)
            for el, val in canon_map[tag].items():
                if len(val.keys())==1:
                    val = t.value[val['mindex']]
                else:
                    val = val.get(t.value[val['mindex']], "uknown: %s" % t.value[val['mindex']])
                setattr(self.__class__, el, property(fget = lambda s, v=val: v))   #make it read only
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]
github achavez / photostreamer-pi / server.py View on Github external
def post_thumb(local_file, s3_file, key):
    """
    Notify photostreamer-server that a new thumbnail photo has been posted
    to S3.
    """
    l.debug("Notifying photostreamer-server of thumbnail photo %s", key)
    tags = exif.parse(local_file)
    filesize = os.path.getsize(local_file)
    payload = {
        "sender" : sender,
        "filesize": filesize,
        "fileid": key,
        "thumbnail": s3_file.generate_url(expires_in=0, query_auth=False),
        "exif": tags
    }
    success = post('/photo/thumb', payload)

exif

Read and modify image EXIF metadata using Python.

MIT
Latest version published 15 days ago

Package Health Score

90 / 100
Full package analysis