How to use the exifread.utils.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 ianare / exif-py / exifread / classes.py View on Github external
logger.warn('MemoryError at position: %s, length: %s', file_position, count)
                            values = ''
                    else:
                        values = ''
                else:
                    values = []
                    signed = (field_type in [6, 8, 9, 10])

                    # XXX investigate
                    # some entries get too big to handle could be malformed
                    # file or problem with self.s2n
                    if count < 1000:
                        for dummy in range(count):
                            if field_type in (5, 10):
                                # a ratio
                                value = Ratio(self.s2n(offset, 4, signed),
                                              self.s2n(offset + 4, 4, signed))
                            elif field_type in (11,12):
                                # a float or double
                                unpack_format = ""
                                if self.endian == 'I':
                                    unpack_format += "<"
                                else:
                                    unpack_format += ">"
                                if field_type == 11:
                                    unpack_format += "f"
                                else:
                                    unpack_format += "d"
                                self.file.seek(self.offset + offset)
                                byte_str = self.file.read(type_length)
                                value = struct.unpack(unpack_format,byte_str)
                            else:
github ianare / exif-py / exifread / utils.py View on Github external
def __new__(cls, numerator=0, denominator=None):
        try:
            self = super(Ratio, cls).__new__(cls, numerator, denominator)
        except ZeroDivisionError:
            self = super(Ratio, cls).__new__(cls)
            self._numerator = numerator
            self._denominator = denominator
        return self
    __new__.doc = Fraction.__new__.__doc__
github ianare / exif-py / exifread / tags / makernote / nikon.py View on Github external
if a == 0:
        return '0 EV'
    if a > 127:
        a = 256 - a
        ret_str = '-'
    else:
        ret_str = '+'
    step = seq[2]  # Assume third value means the step size
    whole = a / step
    a = a % step
    if whole != 0:
        ret_str = '%s%s ' % (ret_str, str(whole))
    if a == 0:
        ret_str += 'EV'
    else:
        r = Ratio(a, step)
        ret_str = ret_str + r.__repr__() + ' EV'
    return ret_str