Ejemplo n.º 1
0
    def test_write_new_struct_in_array(self):
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/test1.xmp")

        with open(filename, 'r') as fptr:
            strbuffer = fptr.read()

        xmp = XMPMeta()
        xmp.parse_from_str(strbuffer)

        prefix = xmp.get_prefix_for_namespace(NS_DC)

        xmp.append_array_item(NS_DC, prefix + 'creator', None, prop_value_is_struct=True)
        xmp.set_property(NS_DC, prefix + 'creator[2]/' + prefix + 'TestProp', '100')
        self.assertTrue(xmp.does_property_exist(NS_DC, prefix + 'creator[2]'))
        prop = xmp.get_property(NS_DC, prefix + 'creator[2]/%sTestProp' % prefix)
        self.assertEqual(prop, '100')

        xpath = prefix + 'creator'
        xmp.set_array_item(NS_DC, xpath, 3, None, prop_value_is_struct=True)
        xpath += '[3]/%sTestProp' % prefix
        xmp.set_property(NS_DC, xpath, '200')
        self.assertTrue(xmp.does_property_exist(NS_DC, xpath))
        prop = xmp.get_property(NS_DC, xpath)
        self.assertEqual(prop, '200')

        xpath = prefix + 'TestStruct/' + prefix + 'TestValue'
        xmp.set_property(NS_DC, xpath, '300')
        self.assertTrue(xmp.does_property_exist(NS_DC, xpath))
        prop = xmp.get_property(NS_DC, xpath)
        self.assertEqual(prop, '300')
Ejemplo n.º 2
0
    def test_write_new_property(self):
        """Corresponds to test-write-new-property.cpp"""

        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/test1.xmp")

        with open(filename, 'r') as fptr:
            strbuffer = fptr.read()

        xmp = XMPMeta()
        xmp.parse_from_str(strbuffer, xmpmeta_wrap=False)

        XMPMeta.register_namespace(NS_CC, "cc")
        reg_prefix = XMPMeta.get_namespace_for_prefix("cc")
        self.assertEqual(reg_prefix, NS_CC)

        reg_prefix = XMPMeta.get_prefix_for_namespace(NS_CC)
        self.assertEqual(reg_prefix, "cc:")

        xmp.set_property(NS_CC, "License", "Foo")
        self.assertEqual(xmp.get_property(NS_CC, "License"), "Foo")

        the_dt = datetime.datetime(2005, 12, 25, 12, 42, 42, tzinfo=pytz.utc)
        xmp.set_property_datetime(NS_EXIF, "DateTimeOriginal", the_dt)
        self.assertEqual(xmp.get_property(NS_EXIF, "DateTimeOriginal"),
                         "2005-12-25T12:42:42")

        prop = xmp.get_property_datetime(NS_EXIF, "DateTimeOriginal")
        self.assertEqual(prop.year, 2005)
        self.assertEqual(prop.minute, 42)
        self.assertEqual(prop.tzinfo, pytz.utc)
Ejemplo n.º 3
0
    def test_write_new_property(self):
        """Corresponds to test-write-new-property.cpp"""

        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/test1.xmp")

        with open(filename, 'r') as fptr:
            strbuffer = fptr.read()

        xmp = XMPMeta()
        xmp.parse_from_str(strbuffer, xmpmeta_wrap=False)

        XMPMeta.register_namespace(NS_CC, "cc")
        reg_prefix = XMPMeta.get_namespace_for_prefix("cc")
        self.assertEqual(reg_prefix, NS_CC)

        reg_prefix = XMPMeta.get_prefix_for_namespace(NS_CC)
        self.assertEqual(reg_prefix, "cc:")

        xmp.set_property(NS_CC, "License", "Foo")
        self.assertEqual(xmp.get_property(NS_CC, "License"), "Foo")

        the_dt = datetime.datetime(2005, 12, 25, 12, 42, 42, tzinfo=pytz.utc)
        xmp.set_property_datetime(NS_EXIF, "DateTimeOriginal", the_dt)
        self.assertEqual(xmp.get_property(NS_EXIF, "DateTimeOriginal"),
                         "2005-12-25T12:42:42")

        prop = xmp.get_property_datetime(NS_EXIF, "DateTimeOriginal")
        self.assertEqual(prop.year, 2005)
        self.assertEqual(prop.minute, 42)
        self.assertEqual(prop.tzinfo, pytz.utc)
Ejemplo n.º 4
0
    def test_write_new_struct_in_array(self):
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/test1.xmp")

        with open(filename, 'r') as fptr:
            strbuffer = fptr.read()

        xmp = XMPMeta()
        xmp.parse_from_str(strbuffer)

        prefix = xmp.get_prefix_for_namespace(NS_DC)

        xmp.append_array_item(NS_DC,
                              prefix + 'creator',
                              None,
                              prop_value_is_struct=True)
        xmp.set_property(NS_DC, prefix + 'creator[2]/' + prefix + 'TestProp',
                         '100')
        self.assertTrue(xmp.does_property_exist(NS_DC, prefix + 'creator[2]'))
        prop = xmp.get_property(NS_DC,
                                prefix + 'creator[2]/%sTestProp' % prefix)
        self.assertEqual(prop, '100')

        xpath = prefix + 'creator'
        xmp.set_array_item(NS_DC, xpath, 3, None, prop_value_is_struct=True)
        xpath += '[3]/%sTestProp' % prefix
        xmp.set_property(NS_DC, xpath, '200')
        self.assertTrue(xmp.does_property_exist(NS_DC, xpath))
        prop = xmp.get_property(NS_DC, xpath)
        self.assertEqual(prop, '200')

        xpath = prefix + 'TestStruct/' + prefix + 'TestValue'
        xmp.set_property(NS_DC, xpath, '300')
        self.assertTrue(xmp.does_property_exist(NS_DC, xpath))
        prop = xmp.get_property(NS_DC, xpath)
        self.assertEqual(prop, '300')
try:
    xmpfile = XMPFiles(file_path=raw_input('image file path:'),
                       open_forupdate=True)
except:
    print('file path invalid!')
    exit()
# xmp = XMPMeta()
xmp = xmpfile.get_xmp()
if xmp is None:
    xmp = XMPMeta()
GPANO = 'GPano'
NS_GPANO = 'http://ns.google.com/photos/1.0/panorama/'
ns = xmp.register_namespace(NS_GPANO, GPANO)
print(ns)
xmp.get_prefix_for_namespace(NS_GPANO)
xmp.set_property_bool(NS_GPANO, 'UsePanaramaViewer', True)
xmp.set_property(NS_GPANO, 'CaptureSoftware', 'Photo Sphere')
xmp.set_property(NS_GPANO, 'StichingSoftware', 'Photo Sphere')
xmp.set_property(NS_GPANO, 'ProjectionType', 'equirectangular')
xmp.set_property_float(NS_GPANO, 'PoseHeadingDegrees', 350.0)
xmp.set_property_float(NS_GPANO, 'InitialViewHeadingDegrees', 90.0)
xmp.set_property_float(NS_GPANO, 'InitialViewPitchDegrees', 0.0)
xmp.set_property_float(NS_GPANO, 'InitialViewRollDegrees', 0.0)
xmp.set_property_float(NS_GPANO, 'InitialHorizontalFOVDegrees', 75.0)
xmp.set_property_int(NS_GPANO, 'CroppedAreaLeftPixels', 0)
xmp.set_property_int(NS_GPANO, 'CroppedAreaTopPixels', 0)
xmp.set_property_int(NS_GPANO, 'CroppedAreaImageWidthPixels', 5100)
xmp.set_property_int(NS_GPANO, 'CroppedAreaImageHeightPixels', 2550)
xmp.set_property_int(NS_GPANO, 'FullPanoWidthPixels', 5100)
xmp.set_property_int(NS_GPANO, 'FullPanoHeightPixels', 2550)