コード例 #1
0
    def test_additional_metadata(self, tmp_path):
        # these should not crash. Seriously dummy data, most of it doesn't make
        # any sense, so we're running up against limits where we're asking
        # libtiff to do stupid things.

        # Get the list of the ones that we should be able to write

        core_items = {
            tag: info
            for tag, info in ((s, TiffTags.lookup(s))
                              for s in TiffTags.LIBTIFF_CORE)
            if info.type is not None
        }

        # Exclude ones that have special meaning
        # that we're already testing them
        with Image.open("Tests/images/hopper_g4.tif") as im:
            for tag in im.tag_v2:
                try:
                    del core_items[tag]
                except KeyError:
                    pass
            del core_items[320]  # colormap is special, tested below

            # Type codes:
            #     2: "ascii",
            #     3: "short",
            #     4: "long",
            #     5: "rational",
            #     12: "double",
            # Type: dummy value
            values = {
                2: "test",
                3: 1,
                4: 2**20,
                5: TiffImagePlugin.IFDRational(100, 1),
                12: 1.05,
            }

            new_ifd = TiffImagePlugin.ImageFileDirectory_v2()
            for tag, info in core_items.items():
                if info.length == 1:
                    new_ifd[tag] = values[info.type]
                if info.length == 0:
                    new_ifd[tag] = tuple(values[info.type] for _ in range(3))
                else:
                    new_ifd[tag] = tuple(values[info.type]
                                         for _ in range(info.length))

            # Extra samples really doesn't make sense in this application.
            del new_ifd[338]

            out = str(tmp_path / "temp.tif")
            TiffImagePlugin.WRITE_LIBTIFF = True

            im.save(out, tiffinfo=new_ifd)

        TiffImagePlugin.WRITE_LIBTIFF = False
コード例 #2
0
    def test_additional_metadata(self):
        # these should not crash. Seriously dummy data, most of it doesn't make
        # any sense, so we're running up against limits where we're asking
        # libtiff to do stupid things.

        # Get the list of the ones that we should be able to write

        core_items = dict((tag, info)
                          for tag, info in [(s, TiffTags.lookup(s))
                                            for s in TiffTags.LIBTIFF_CORE]
                          if info.type is not None)

        # Exclude ones that have special meaning
        # that we're already testing them
        im = Image.open('Tests/images/hopper_g4.tif')
        for tag in im.tag_v2.keys():
            try:
                del (core_items[tag])
            except:
                pass

        # Type codes:
        #     2: "ascii",
        #     3: "short",
        #     4: "long",
        #     5: "rational",
        #     12: "double",
        # type: dummy value
        values = {
            2: 'test',
            3: 1,
            4: 2**20,
            5: TiffImagePlugin.IFDRational(100, 1),
            12: 1.05
        }

        new_ifd = TiffImagePlugin.ImageFileDirectory_v2()
        for tag, info in core_items.items():
            if info.length == 1:
                new_ifd[tag] = values[info.type]
            if info.length == 0:
                new_ifd[tag] = tuple(values[info.type] for _ in range(3))
            else:
                new_ifd[tag] = tuple(values[info.type]
                                     for _ in range(info.length))

        # Extra samples really doesn't make sense in this application.
        del (new_ifd[338])

        out = self.tempfile("temp.tif")
        TiffImagePlugin.WRITE_LIBTIFF = True

        im.save(out, tiffinfo=new_ifd)

        TiffImagePlugin.WRITE_LIBTIFF = False
コード例 #3
0
ファイル: test_file_libtiff.py プロジェクト: hugovk/Pillow
    def test_additional_metadata(self):
        # these should not crash. Seriously dummy data, most of it doesn't make
        # any sense, so we're running up against limits where we're asking
        # libtiff to do stupid things.

        # Get the list of the ones that we should be able to write

        core_items = {tag: info for tag, info in ((s, TiffTags.lookup(s)) for s
                                                  in TiffTags.LIBTIFF_CORE)
                      if info.type is not None}

        # Exclude ones that have special meaning
        # that we're already testing them
        im = Image.open('Tests/images/hopper_g4.tif')
        for tag in im.tag_v2:
            try:
                del core_items[tag]
            except KeyError:
                pass

        # Type codes:
        #     2: "ascii",
        #     3: "short",
        #     4: "long",
        #     5: "rational",
        #     12: "double",
        # Type: dummy value
        values = {2: 'test',
                  3: 1,
                  4: 2**20,
                  5: TiffImagePlugin.IFDRational(100, 1),
                  12: 1.05}

        new_ifd = TiffImagePlugin.ImageFileDirectory_v2()
        for tag, info in core_items.items():
            if info.length == 1:
                new_ifd[tag] = values[info.type]
            if info.length == 0:
                new_ifd[tag] = tuple(values[info.type] for _ in range(3))
            else:
                new_ifd[tag] = tuple(values[info.type]
                                     for _ in range(info.length))

        # Extra samples really doesn't make sense in this application.
        del new_ifd[338]

        out = self.tempfile("temp.tif")
        TiffImagePlugin.WRITE_LIBTIFF = True

        im.save(out, tiffinfo=new_ifd)

        TiffImagePlugin.WRITE_LIBTIFF = False