Exemplo n.º 1
0
    def test_xmpfiles_write(self):
        """According to test-xmpfiles-write.cpp"""
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/BlueSquare.jpg")

        fmt = exempi.files_check_file_format(filename)
        self.assertEqual(fmt, libxmp.consts.XMP_FT_JPEG)

        xfptr = exempi.files_open_new(filename, XMP_OPEN_READ)
        xmp = exempi.files_get_new_xmp(xfptr)
        exempi.files_free(xfptr)

        with tempfile.NamedTemporaryFile(suffix=".jpg") as tfile:
            shutil.copyfile(filename, tfile.name)

            xfptr = exempi.files_open_new(tfile.name, XMP_OPEN_FORUPDATE)

            exempi.set_property(xmp, NS_PHOTOSHOP, "ICCProfile", "foo", 0)
            self.assertTrue(exempi.files_can_put_xmp(xfptr, xmp))
            exempi.files_put_xmp(xfptr, xmp)
            exempi.free(xmp)
            exempi.files_close(xfptr, XMP_CLOSE_SAFEUPDATE)
            exempi.files_free(xfptr)

            xfptr = exempi.files_open_new(tfile.name, XMP_OPEN_READ)
            xmp = exempi.files_get_new_xmp(xfptr)
            the_prop, _ = exempi.get_property(xmp, NS_PHOTOSHOP, "ICCProfile")
            self.assertEqual("foo", the_prop)

            exempi.free(xmp)
            exempi.files_close(xfptr, XMP_CLOSE_NOOPTION)
            exempi.files_free(xfptr)
Exemplo n.º 2
0
 def get_xmp(self, tag):
     xfptr = exempi.files_open_new(self.path, XMP_OPEN_READ)
     xmp = exempi.files_get_new_xmp(xfptr)
     the_prop, _ = exempi.get_property(xmp, NS_PHOTOSHOP, tag)
     exempi.free(xmp)
     exempi.files_close(xfptr, XMP_CLOSE_NOOPTION)
     exempi.files_free(xfptr)
Exemplo n.º 3
0
    def test_xmpfiles_write(self):
        """According to test-xmpfiles-write.cpp"""
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/BlueSquare.jpg")

        fmt = exempi.files_check_file_format(filename)
        self.assertEqual(fmt, libxmp.consts.XMP_FT_JPEG)

        xfptr = exempi.files_open_new(filename, XMP_OPEN_READ)
        xmp = exempi.files_get_new_xmp(xfptr)
        exempi.files_free(xfptr)

        with tempfile.NamedTemporaryFile(suffix=".jpg") as tfile:
            shutil.copyfile(filename, tfile.name)

            xfptr = exempi.files_open_new(tfile.name, XMP_OPEN_FORUPDATE)

            exempi.set_property(xmp, NS_PHOTOSHOP, "ICCProfile", "foo", 0)
            self.assertTrue(exempi.files_can_put_xmp(xfptr, xmp))
            exempi.files_put_xmp(xfptr, xmp)
            exempi.free(xmp)
            exempi.files_close(xfptr, XMP_CLOSE_SAFEUPDATE)
            exempi.files_free(xfptr)

            xfptr = exempi.files_open_new(tfile.name, XMP_OPEN_READ)
            xmp = exempi.files_get_new_xmp(xfptr)
            the_prop, _ = exempi.get_property(xmp, NS_PHOTOSHOP, "ICCProfile")
            self.assertEqual("foo", the_prop)

            exempi.free(xmp)
            exempi.files_close(xfptr, XMP_CLOSE_NOOPTION)
            exempi.files_free(xfptr)
Exemplo n.º 4
0
 def write_xmp(self, tag, value):
     xfptr = exempi.files_open_new(self.path, XMP_OPEN_FORUPDATE)
     xmp = exempi.files_get_new_xmp(xfptr)
     if xmp is not None:
         exempi.set_property(xmp, NS_PHOTOSHOP, tag, value, 0)
         exempi.files_put_xmp(xfptr, xmp)
         exempi.free(xmp)
     exempi.files_close(xfptr, XMP_CLOSE_SAFEUPDATE)
     exempi.files_free(xfptr)
Exemplo n.º 5
0
    def test_tiff_leak(self):
        """Corresponds to test-tiff-leak.cpp"""
        orig_file = pkg_resources.resource_filename(__name__,
                                                    "samples/BlueSquare.tif")

        with tempfile.NamedTemporaryFile(suffix='.tif') as tfile:
            shutil.copyfile(orig_file, tfile.name)

            xfptr = exempi.files_open_new(tfile.name, XMP_OPEN_FORUPDATE)

            xmp = exempi.files_get_new_xmp(xfptr)
            exempi.set_localized_text(xmp, NS_DC, "description", "en", "en-US",
                                      "foo", 0)
            exempi.files_put_xmp(xfptr, xmp)
            exempi.files_close(xfptr, XMP_CLOSE_NOOPTION)
            exempi.free(xmp)
            exempi.files_free(xfptr)
        self.assertTrue(True)
Exemplo n.º 6
0
    def test_tiff_leak(self):
        """Corresponds to test-tiff-leak.cpp"""
        orig_file = pkg_resources.resource_filename(__name__,
                                                    "samples/BlueSquare.tif")

        with tempfile.NamedTemporaryFile(suffix='.tif') as tfile:
            shutil.copyfile(orig_file, tfile.name)

            xfptr = exempi.files_open_new(tfile.name, XMP_OPEN_FORUPDATE)

            xmp = exempi.files_get_new_xmp(xfptr)
            exempi.set_localized_text(xmp, NS_DC, "description", "en", "en-US",
                                      "foo", 0)
            exempi.files_put_xmp(xfptr, xmp)
            exempi.files_close(xfptr, XMP_CLOSE_NOOPTION)
            exempi.free(xmp)
            exempi.files_free(xfptr)
        self.assertTrue(True)