How to use pyexiv2 - 10 common examples

To help you get started, we’ve selected a few pyexiv2 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 ilektrojohn / creepy / creepy / urlanalyzer.py View on Github external
if not PYEXIV_AVAILABLE:
            return []

        def calc(k): return [(float(n)/float(d)) for n,d in [k.split("/")]][0]
        def degtodec(a): return a[0]+a[1]/60+a[2]/3600
        def format_coordinates(string):
            return degtodec([(calc(i)) for i in (string.split(' ')) if ("/" in i)])
        def format_coordinates_alter(tuple):
            return degtodec(((float(tuple[0].numerator)/float(tuple[0].denominator)), (float(tuple[1].numerator)/float(tuple[1].denominator)), (float(tuple[2].numerator)/float(tuple[2].denominator))))
            
        
        try:
            #Check if pyexiv2 v0.3 is installed
            if 'ImageMetadata' in dir(pyexiv2):
                exif_data = pyexiv2.ImageMetadata(temp_file)
                exif_data.read()
                keys = exif_data.exif_keys
                if "Exif.GPSInfo.GPSLatitude" in keys :
                    coordinates = {}
                    coordinates['from'] = 'exif'
                    coordinates['context'] = ('https://twitter.com/%s/status/%s' % (tweet.user.screen_name, tweet.id) , 'Location retrieved from image exif metadata .\n Tweet was %s \n ' % (tweet.text))
                    coordinates['time'] = datetime.fromtimestamp(mktime(time.strptime(exif_data['Exif.Image.DateTime'].raw_value, "%Y:%m:%d %H:%M:%S")))
                    coordinates['latitude'] = format_coordinates(exif_data['Exif.GPSInfo.GPSLatitude'].raw_value)
                    coordinates['realname'] = tweet.user.name
                    lat_ref = exif_data['Exif.GPSInfo.GPSLatitudeRef'].raw_value
                    if lat_ref == 'S':
                        coordinates['latitude'] = -coordinates['latitude']
                    coordinates['longitude'] = format_coordinates(exif_data['Exif.GPSInfo.GPSLongitude'].raw_value)
                    long_ref = exif_data['Exif.GPSInfo.GPSLongitudeRef'].raw_value
                    if long_ref == 'W':
                        coordinates['longitude'] = -coordinates['longitude']
github UASLab / ImageAnalysis / lib / archive / ATICorrelate.py View on Github external
def load_images(self):
        files = []
        self.pictures = []
        path = self.image_dir
        for file in os.listdir(path):
            if fnmatch.fnmatch(file, '*.jpg') or fnmatch.fnmatch(file, '*.JPG'):
                files.append(file)
        files.sort()
        last_trigger = 0.0
        interval = 0
        for f in files:
            name = path + "/" + f
            print name
            exif = pyexiv2.ImageMetadata(name)
            exif.read()
            # print exif.exif_keys
            strdate, strtime = str(exif['Exif.Image.DateTime'].value).split()
            year, month, day = strdate.split('-')
            formated = year + "/" + month + "/" + day + " " + strtime + " UTC"
            result, unixtimestr = commands.getstatusoutput('date -d "' + formated + '" "+%s"' )
            unixtime = float(unixtimestr)
            # print f + ": " + strdate + ", " + strtime + ", " + unixtimestr

            if last_trigger > 0.0:
                interval = unixtime - last_trigger

            self.pictures.append( (unixtime, interval, f) )

            last_trigger = unixtime
github spillz / picty / utils / metadata-viewer.py View on Github external
def open_image(self,path=''):
        if not path:
            default=''
            if self.path:
                default=os.path.split(self.path)[0]
            path=file_dialog(default=default)
            if not path:
                return
        self.path=os.path.abspath(path)
        # Load the image, read the metadata
        try:
            metadata = pyexiv2.ImageMetadata(self.path)
            metadata.read()
        except:
            self.imgwidget.clear()
            self.model.clear()
            self.set_title("Metadata Viewer")
            return

        self.set_title("Metadata Viewer - %s"%(path,))
        #extract the thumbnail data
        previews = metadata.previews
        if previews:
            preview = previews[-1]
            # Get the largest preview available
            # Create a pixbuf loader to read the thumbnail data
            pbloader = gtk.gdk.PixbufLoader()
            pbloader.write(preview.data)
github gramps-project / addons-source / contrib / ImageMetadataGramplet / ImageMetadataGramplet.py View on Github external
def string_to_rational(coordinate):
    """
    convert string to rational variable for GPS
    """

    if '.' in coordinate:
        value1, value2 = coordinate.split('.')
        return pyexiv2.Rational(int(float(value1 + value2)), 10**len(value2))
    else:
        return pyexiv2.Rational(int(coordinate), 1)
github gramps-project / addons-source / EditExifMetadata / editexifmetadata.py View on Github external
def string_to_rational(coordinate):
    """
    convert string to rational variable for GPS
    """
    if '.' in coordinate:
        value1, value2 = coordinate.split('.')
        return pyexiv2.Rational(int(float(value1 + value2)), 10**len(value2))
    else:
        return pyexiv2.Rational(int(coordinate), 1)
github gramps-project / addons-source / contrib / ImageMetadataGramplet / ImageMetadataGramplet.py View on Github external
def string_to_rational(coordinate):
    """
    convert string to rational variable for GPS
    """

    if '.' in coordinate:
        value1, value2 = coordinate.split('.')
        return pyexiv2.Rational(int(float(value1 + value2)), 10**len(value2))
    else:
        return pyexiv2.Rational(int(coordinate), 1)
github gramps-project / gramps / gramps / plugins / gramplet / editexifmetadata.py View on Github external
def string_to_rational(coordinate):
    """
    convert string to rational variable for GPS
    """
    if '.' in coordinate:
        value1, value2 = coordinate.split('.')
        return pyexiv2.Rational(int(float(value1 + value2)), 10**len(value2))
    else:
        return pyexiv2.Rational(int(coordinate), 1)
github gramps-project / addons-source / EditExifMetadata / editexifmetadata.py View on Github external
def string_to_rational(coordinate):
    """
    convert string to rational variable for GPS
    """
    if '.' in coordinate:
        value1, value2 = coordinate.split('.')
        return pyexiv2.Rational(int(float(value1 + value2)), 10**len(value2))
    else:
        return pyexiv2.Rational(int(coordinate), 1)
github LeoHsiao1 / pyexiv2 / pyexiv2 / core.py View on Github external
def set_log_level(level=2):
    """
    Set the level of handling logs. There are five levels of handling logs:
        0 : debug
        1 : info
        2 : warn
        3 : error
        4 : mute
    """
    if level in [0, 1, 2, 3, 4]:
        api.set_log_level(level)
    else:
        raise ValueError('Invalid log level.')


api.init()
set_log_level(2)
github mapillary / OpenSfM / opensfm / geotag_from_gpx.py View on Github external
def add_exif_using_timestamp(filename, points, offset_time=0, timestamp=None, orientation=1, image_description=None):
    '''
    Find lat, lon and bearing of filename and write to EXIF.
    '''

    metadata = pyexiv2.ImageMetadata(filename)
    metadata.read()
    if timestamp:
        metadata['Exif.Photo.DateTimeOriginal'] = timestamp

    t = metadata['Exif.Photo.DateTimeOriginal'].value

    # subtract offset in s beween gpx time and exif time
    t = t - datetime.timedelta(seconds=offset_time)

    try:
        lat, lon, bearing, elevation = interpolate_lat_lon(points, t)

        lat_deg = to_deg(lat, ["S", "N"])
        lon_deg = to_deg(lon, ["W", "E"])

        # convert decimal coordinates into degrees, minutes and seconds as fractions for EXIF