def test_makernote_types(self): # Makernote tags not attached to an image have an Undefined type by # default. When read from an existing image though, their type should be # correctly set (see https://bugs.launchpad.net/pyexiv2/+bug/781464). tag1 = ExifTag('Exif.Pentax.PreviewResolution') tag1.raw_value = '640 480' self.assertEqual(tag1.type, 'Undefined') self.failUnlessRaises(ValueError, getattr, tag1, 'value') tag2 = ExifTag('Exif.Pentax.CameraInfo') tag2.raw_value = '76830 20070527 2 1 4228109' self.assertEqual(tag2.type, 'Undefined') self.failUnlessRaises(ValueError, getattr, tag2, 'value') filepath = testutils.get_absolute_file_path( os.path.join('data', 'pentax-makernote.jpg')) checksum = '646804b309a4a2d31feafe9bffc5d7f0' self.assert_(testutils.CheckFileSum(filepath, checksum)) metadata = ImageMetadata(filepath) metadata.read() tag1 = metadata[tag1.key] self.assertEqual(tag1.type, 'Short') self.assertEqual(tag1.value, [640, 480]) tag2 = metadata[tag2.key] self.assertEqual(tag2.type, 'Long') self.assertEqual(tag2.value, [76830L, 20070527L, 2L, 1L, 4228109L])
def _read_image(self, filename): filepath = testutils.get_absolute_file_path( os.path.join('data', filename)) self.assert_(testutils.CheckFileSum(filepath, self.checksums[filename])) m = ImageMetadata(filepath) m.read() return m
def testReadMetadata(self): """ Perform various tests on reading the metadata contained in a file. """ # Check that the reference file is not corrupted filename = os.path.join('data', 'smiley1.jpg') filepath = testutils.get_absolute_file_path(filename) md5sum = 'c066958457c685853293058f9bf129c1' self.assertCorrectFile(filepath, md5sum) # Read the image metadata image = pyexiv2.ImageMetadata(filepath) image.read() # Exhaustive tests on the values of EXIF metadata exifTags = [('Exif.Image.ImageDescription', str, 'Well it is a smiley that happens to be green'), ('Exif.Image.XResolution', FRACTION, make_fraction(72, 1)), ('Exif.Image.YResolution', FRACTION, make_fraction(72, 1)), ('Exif.Image.ResolutionUnit', int, 2), ('Exif.Image.Software', str, 'ImageReady'), ('Exif.Image.DateTime', datetime.datetime, datetime.datetime(2004, 7, 13, 21, 23, 44)), ('Exif.Image.Artist', str, 'No one'), ('Exif.Image.Copyright', str, ''), ('Exif.Image.ExifTag', long, 226L), ('Exif.Photo.Flash', int, 80), ('Exif.Photo.PixelXDimension', long, 167L), ('Exif.Photo.PixelYDimension', long, 140L)] self.assertEqual(image.exif_keys, [tag[0] for tag in exifTags]) for key, ktype, value in exifTags: self.check_type_and_value(image[key], ktype, value) # Exhaustive tests on the values of IPTC metadata iptcTags = [('Iptc.Application2.Caption', str, ['yelimS green faced dude (iptc caption)']), ('Iptc.Application2.Writer', str, ['Nobody']), ('Iptc.Application2.Byline', str, ['Its me']), ('Iptc.Application2.ObjectName', str, ['GreeenDude']), ('Iptc.Application2.DateCreated', datetime.date, [datetime.date(2004, 7, 13)]), ('Iptc.Application2.City', str, ['Seattle']), ('Iptc.Application2.ProvinceState', str, ['WA']), ('Iptc.Application2.CountryName', str, ['USA']), ('Iptc.Application2.Category', str, ['Things']), ('Iptc.Application2.Keywords', str, ['Green', 'Smiley', 'Dude']), ('Iptc.Application2.Copyright', str, ['\xa9 2004 Nobody'])] self.assertEqual(image.iptc_keys, [tag[0] for tag in iptcTags]) for key, ktype, values in iptcTags: self.check_type_and_values(image[key], ktype, values)
def testReadMetadata(self): """ Perform various tests on reading the metadata contained in a file. """ # Check that the reference file is not corrupted filename = os.path.join('data', 'DSCF_0273.JPG') filepath = testutils.get_absolute_file_path(filename) md5sum = '64d4b7eab1e78f1f6bfb3c966e99eef2' #self.assertCorrectFile(filepath, md5sum) # Read the image metadata image = pyexiv2.ImageMetadata(filepath) image.read() # Exhaustive tests on the values of EXIF metadata exifTags = [('Exif.Image.Software', str, 'Digital Camera FinePix S4800 Ver1.00'), ('Exif.Image.XResolution', FRACTION, make_fraction(72, 1)), ('Exif.Image.YResolution', FRACTION, make_fraction(72, 1)), ('Exif.Image.ResolutionUnit', int, 2), ('Exif.Image.Software', str, 'Digital Camera FinePix S4800 Ver1.00'), ('Exif.Image.DateTime', datetime.datetime, datetime.datetime(2015, 1, 17, 13, 53, 3)), ('Exif.Image.Artist', str, 'Vincent Vande Vyvre'), ('Exif.Photo.ApertureValue', FRACTION, make_fraction(6, 1)), ('Exif.Photo.FNumber', FRACTION, make_fraction(8, 1)), ('Exif.Photo.PixelXDimension', int, 250), ('Exif.Photo.PixelYDimension', int, 140)] for key, ktype, value in exifTags: self.check_type_and_value(image[key], ktype, value) # Exhaustive tests on the values of IPTC metadata iptcTags = [('Iptc.Application2.Caption', str, ['S']), ('Iptc.Application2.Byline', str, ['Vincent Vande Vyvre']), ('Iptc.Application2.0x00d7', str, ['www.oqapy.eu']), ('Iptc.Application2.Keywords', str, ['bruxelles botanique']), ('Iptc.Application2.Copyright', str, ['2013 Vincent Vande Vyvre'])] for key, ktype, values in iptcTags: self.check_type_and_values(image[key], ktype, values)
def test_makernote_types(self): # Makernote tags not attached to an image have an Undefined type by # default. When read from an existing image though, their type should be # correctly set (see https://bugs.launchpad.net/pyexiv2/+bug/781464). tag1 = ExifTag('Exif.Pentax.PreviewResolution') tag1.raw_value = '640 480' self.assertEqual(tag1.type, 'Undefined') self.failUnlessRaises(ValueError, getattr, tag1, 'value') tag2 = ExifTag('Exif.Pentax.CameraInfo') tag2.raw_value = '76830 20070527 2 1 4228109' self.assertEqual(tag2.type, 'Undefined') self.failUnlessRaises(ValueError, getattr, tag2, 'value') filepath = testutils.get_absolute_file_path(os.path.join('data', 'pentax-makernote.jpg')) checksum = '646804b309a4a2d31feafe9bffc5d7f0' self.assert_(testutils.CheckFileSum(filepath, checksum)) metadata = ImageMetadata(filepath) metadata.read() tag1 = metadata[tag1.key] self.assertEqual(tag1.type, 'Short') self.assertEqual(tag1.value, [640, 480]) tag2 = metadata[tag2.key] self.assertEqual(tag2.type, 'Long') self.assertEqual(tag2.value, [76830L, 20070527L, 2L, 1L, 4228109L])
def testReadMetadataXMP(self): filename = os.path.join('data', 'exiv2-bug540.jpg') filepath = testutils.get_absolute_file_path(filename) md5sum = '64d4b7eab1e78f1f6bfb3c966e99eef2' self.assertCorrectFile(filepath, md5sum) # Read the image metadata image = pyexiv2.ImageMetadata(filepath) image.read() xmpTags = [ ('Xmp.dc.creator', list, [u'Ian Britton']), ('Xmp.dc.description', dict, { u'x-default': u'Communications' }), ('Xmp.dc.rights', dict, { u'x-default': u'ian Britton - FreeFoto.com' }), ('Xmp.dc.source', unicode, u'FreeFoto.com'), ('Xmp.dc.subject', list, [u'Communications']), ('Xmp.dc.title', dict, { u'x-default': u'Communications' }), ('Xmp.exif.ApertureValue', FRACTION, make_fraction(8, 1)), ('Xmp.exif.BrightnessValue', FRACTION, make_fraction(333, 1280)), ('Xmp.exif.ColorSpace', int, 1), ('Xmp.exif.DateTimeOriginal', datetime.datetime, datetime.datetime(2002, 7, 13, 15, 58, 28, tzinfo=pyexiv2.utils.FixedOffset())), ('Xmp.exif.ExifVersion', unicode, u'0200'), ('Xmp.exif.ExposureBiasValue', FRACTION, make_fraction(-13, 20)), ('Xmp.exif.ExposureProgram', int, 4), ('Xmp.exif.FNumber', FRACTION, make_fraction(3, 5)), ('Xmp.exif.FileSource', int, 0), ('Xmp.exif.FlashpixVersion', unicode, u'0100'), ('Xmp.exif.FocalLength', FRACTION, make_fraction(0, 1)), ('Xmp.exif.FocalPlaneResolutionUnit', int, 2), ('Xmp.exif.FocalPlaneXResolution', FRACTION, make_fraction(3085, 256)), ('Xmp.exif.FocalPlaneYResolution', FRACTION, make_fraction(3085, 256)), ('Xmp.exif.GPSLatitude', pyexiv2.utils.GPSCoordinate, pyexiv2.utils.GPSCoordinate.from_string('54,59.380000N')), ('Xmp.exif.GPSLongitude', pyexiv2.utils.GPSCoordinate, pyexiv2.utils.GPSCoordinate.from_string('1,54.850000W')), ('Xmp.exif.GPSMapDatum', unicode, u'WGS84'), ('Xmp.exif.GPSTimeStamp', datetime.datetime, datetime.datetime(2002, 7, 13, 14, 58, 24, tzinfo=pyexiv2.utils.FixedOffset())), ('Xmp.exif.GPSVersionID', unicode, u'2.0.0.0'), ('Xmp.exif.ISOSpeedRatings', list, [0]), ('Xmp.exif.MeteringMode', int, 5), ('Xmp.exif.PixelXDimension', int, 2400), ('Xmp.exif.PixelYDimension', int, 1600), ('Xmp.exif.SceneType', int, 0), ('Xmp.exif.SensingMethod', int, 2), ('Xmp.exif.ShutterSpeedValue', FRACTION, make_fraction(30827, 3245)), ('Xmp.pdf.Keywords', unicode, u'Communications'), ('Xmp.photoshop.AuthorsPosition', unicode, u'Photographer'), ('Xmp.photoshop.CaptionWriter', unicode, u'Ian Britton'), ('Xmp.photoshop.Category', unicode, u'BUS'), ('Xmp.photoshop.City', unicode, u' '), ('Xmp.photoshop.Country', unicode, u'Ubited Kingdom'), ('Xmp.photoshop.Credit', unicode, u'Ian Britton'), ('Xmp.photoshop.DateCreated', datetime.date, datetime.date(2002, 6, 20)), ('Xmp.photoshop.Headline', unicode, u'Communications'), ('Xmp.photoshop.State', unicode, u' '), ('Xmp.photoshop.SupplementalCategories', list, [u'Communications' ]), ('Xmp.photoshop.Urgency', int, 5), ('Xmp.tiff.Artist', unicode, u'Ian Britton'), ('Xmp.tiff.BitsPerSample', list, [8]), ('Xmp.tiff.Compression', int, 6), ('Xmp.tiff.Copyright', dict, { u'x-default': u'ian Britton - FreeFoto.com' }), ('Xmp.tiff.ImageDescription', dict, { u'x-default': u'Communications' }), ('Xmp.tiff.ImageLength', int, 400), ('Xmp.tiff.ImageWidth', int, 600), ('Xmp.tiff.Make', unicode, u'FUJIFILM'), ('Xmp.tiff.Model', unicode, u'FinePixS1Pro'), ('Xmp.tiff.Orientation', int, 1), ('Xmp.tiff.ResolutionUnit', int, 2), ('Xmp.tiff.Software', unicode, u'Adobe Photoshop 7.0'), ('Xmp.tiff.XResolution', FRACTION, make_fraction(300, 1)), ('Xmp.tiff.YCbCrPositioning', int, 2), ('Xmp.tiff.YResolution', FRACTION, make_fraction(300, 1)), ('Xmp.xmp.CreateDate', datetime.datetime, datetime.datetime(2002, 7, 13, 15, 58, 28, tzinfo=pyexiv2.utils.FixedOffset())), ('Xmp.xmp.ModifyDate', datetime.datetime, datetime.datetime(2002, 7, 19, 13, 28, 10, tzinfo=pyexiv2.utils.FixedOffset())), ('Xmp.xmpBJ.JobRef', list, []), ('Xmp.xmpBJ.JobRef[1]', str, ''), ('Xmp.xmpBJ.JobRef[1]/stJob:name', str, 'Photographer'), ('Xmp.xmpMM.DocumentID', str, 'adobe:docid:photoshop:84d4dba8-9b11-11d6-895d-c4d063a70fb0'), ('Xmp.xmpRights.Marked', bool, True), ('Xmp.xmpRights.WebStatement', str, 'www.freefoto.com') ] self.assertEqual(image.xmp_keys, [tag[0] for tag in xmpTags]) for key, ktype, value in xmpTags: self.check_type_and_value(image[key], ktype, value)
def testReadMetadataXMP(self): filename = os.path.join('data', 'exiv2-bug540.jpg') filepath = testutils.get_absolute_file_path(filename) md5sum = '64d4b7eab1e78f1f6bfb3c966e99eef2' self.assertCorrectFile(filepath, md5sum) # Read the image metadata image = pyexiv2.ImageMetadata(filepath) image.read() xmpTags = [('Xmp.dc.creator', list, [u'Ian Britton']), ('Xmp.dc.description', dict, {u'x-default': u'Communications'}), ('Xmp.dc.rights', dict, {u'x-default': u'ian Britton - FreeFoto.com'}), ('Xmp.dc.source', unicode, u'FreeFoto.com'), ('Xmp.dc.subject', list, [u'Communications']), ('Xmp.dc.title', dict, {u'x-default': u'Communications'}), ('Xmp.exif.ApertureValue', FRACTION, make_fraction(8, 1)), ('Xmp.exif.BrightnessValue', FRACTION, make_fraction(333, 1280)), ('Xmp.exif.ColorSpace', int, 1), ('Xmp.exif.DateTimeOriginal', datetime.datetime, datetime.datetime(2002, 7, 13, 15, 58, 28, tzinfo=pyexiv2.utils.FixedOffset())), ('Xmp.exif.ExifVersion', unicode, u'0200'), ('Xmp.exif.ExposureBiasValue', FRACTION, make_fraction(-13, 20)), ('Xmp.exif.ExposureProgram', int, 4), ('Xmp.exif.FNumber', FRACTION, make_fraction(3, 5)), ('Xmp.exif.FileSource', int, 0), ('Xmp.exif.FlashpixVersion', unicode, u'0100'), ('Xmp.exif.FocalLength', FRACTION, make_fraction(0, 1)), ('Xmp.exif.FocalPlaneResolutionUnit', int, 2), ('Xmp.exif.FocalPlaneXResolution', FRACTION, make_fraction(3085, 256)), ('Xmp.exif.FocalPlaneYResolution', FRACTION, make_fraction(3085, 256)), ('Xmp.exif.GPSLatitude', pyexiv2.utils.GPSCoordinate, pyexiv2.utils.GPSCoordinate.from_string('54,59.380000N')), ('Xmp.exif.GPSLongitude', pyexiv2.utils.GPSCoordinate, pyexiv2.utils.GPSCoordinate.from_string('1,54.850000W')), ('Xmp.exif.GPSMapDatum', unicode, u'WGS84'), ('Xmp.exif.GPSTimeStamp', datetime.datetime, datetime.datetime(2002, 7, 13, 14, 58, 24, tzinfo=pyexiv2.utils.FixedOffset())), ('Xmp.exif.GPSVersionID', unicode, u'2.0.0.0'), ('Xmp.exif.ISOSpeedRatings', list, [0]), ('Xmp.exif.MeteringMode', int, 5), ('Xmp.exif.PixelXDimension', int, 2400), ('Xmp.exif.PixelYDimension', int, 1600), ('Xmp.exif.SceneType', int, 0), ('Xmp.exif.SensingMethod', int, 2), ('Xmp.exif.ShutterSpeedValue', FRACTION, make_fraction(30827, 3245)), ('Xmp.pdf.Keywords', unicode, u'Communications'), ('Xmp.photoshop.AuthorsPosition', unicode, u'Photographer'), ('Xmp.photoshop.CaptionWriter', unicode, u'Ian Britton'), ('Xmp.photoshop.Category', unicode, u'BUS'), ('Xmp.photoshop.City', unicode, u' '), ('Xmp.photoshop.Country', unicode, u'Ubited Kingdom'), ('Xmp.photoshop.Credit', unicode, u'Ian Britton'), ('Xmp.photoshop.DateCreated', datetime.date, datetime.date(2002, 6, 20)), ('Xmp.photoshop.Headline', unicode, u'Communications'), ('Xmp.photoshop.State', unicode, u' '), ('Xmp.photoshop.SupplementalCategories', list, [u'Communications']), ('Xmp.photoshop.Urgency', int, 5), ('Xmp.tiff.Artist', unicode, u'Ian Britton'), ('Xmp.tiff.BitsPerSample', list, [8]), ('Xmp.tiff.Compression', int, 6), ('Xmp.tiff.Copyright', dict, {u'x-default': u'ian Britton - FreeFoto.com'}), ('Xmp.tiff.ImageDescription', dict, {u'x-default': u'Communications'}), ('Xmp.tiff.ImageLength', int, 400), ('Xmp.tiff.ImageWidth', int, 600), ('Xmp.tiff.Make', unicode, u'FUJIFILM'), ('Xmp.tiff.Model', unicode, u'FinePixS1Pro'), ('Xmp.tiff.Orientation', int, 1), ('Xmp.tiff.ResolutionUnit', int, 2), ('Xmp.tiff.Software', unicode, u'Adobe Photoshop 7.0'), ('Xmp.tiff.XResolution', FRACTION, make_fraction(300, 1)), ('Xmp.tiff.YCbCrPositioning', int, 2), ('Xmp.tiff.YResolution', FRACTION, make_fraction(300, 1)), ('Xmp.xmp.CreateDate', datetime.datetime, datetime.datetime(2002, 7, 13, 15, 58, 28, tzinfo=pyexiv2.utils.FixedOffset())), ('Xmp.xmp.ModifyDate', datetime.datetime, datetime.datetime(2002, 7, 19, 13, 28, 10, tzinfo=pyexiv2.utils.FixedOffset())), ('Xmp.xmpBJ.JobRef', list, []), ('Xmp.xmpBJ.JobRef[1]', str, ''), ('Xmp.xmpBJ.JobRef[1]/stJob:name', str, 'Photographer'), ('Xmp.xmpMM.DocumentID', str, 'adobe:docid:photoshop:84d4dba8-9b11-11d6-895d-c4d063a70fb0'), ('Xmp.xmpRights.Marked', bool, True), ('Xmp.xmpRights.WebStatement', str, 'www.freefoto.com')] self.assertEqual(image.xmp_keys, [tag[0] for tag in xmpTags]) for key, ktype, value in xmpTags: self.check_type_and_value(image[key], ktype, value)
def _read_image(self, filename): filepath = testutils.get_absolute_file_path(os.path.join('data', filename)) self.assert_(testutils.CheckFileSum(filepath, self.checksums[filename])) m = ImageMetadata(filepath) m.read() return m
def setUp(self): filename = os.path.join('data', 'smiley1.jpg') self.filepath = testutils.get_absolute_file_path(filename) self.md5sum = 'c066958457c685853293058f9bf129c1' self.assert_(testutils.CheckFileSum(self.filepath, self.md5sum))
def setUp(self): filename = os.path.join("data", "smiley1.jpg") self.filepath = testutils.get_absolute_file_path(filename) self.md5sum = "c066958457c685853293058f9bf129c1" self.assert_(testutils.CheckFileSum(self.filepath, self.md5sum))