How to use the exifread.Ratio function in ExifRead

To help you get started, we’ve selected a few ExifRead 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 openstreetcam / upload-scripts / exif_processing.py View on Github external
def gps_timestamp(gps_data: {str: str}) -> Optional[float]:
    """Exif gps time from gps_data represented by gps tags found in image exif.
    In exif there are values giving the hour, minute, and second.
    This is UTC time"""
    if ExifTags.GPS_TIMESTAMP.value in gps_data:
        # timestamp exists
        _timestamp = gps_data[ExifTags.GPS_TIMESTAMP.value]
        hours: exifread.Ratio = _timestamp.values[0]
        minutes: exifread.Ratio = _timestamp.values[1]
        seconds: exifread.Ratio = _timestamp.values[2]

        day_timestamp = hours.num / hours.den * 3600 + \
                        minutes.num / minutes.den * 60 + \
                        seconds.num / seconds.den

        if ExifTags.GPS_DATE_STAMP.value in gps_data:
            # this tag is the one present in the exif documentation
            # but from experience ExifTags.GPS_DATE is replacing this tag
            gps_date = gps_data[ExifTags.GPS_DATE_STAMP.value].values
            date_timestamp = datetime.datetime.strptime(gps_date, "%Y:%m:%d").timestamp()

            return day_timestamp + date_timestamp

        if ExifTags.GPS_DATE.value in gps_data: