当前位置: 首页>>代码示例>>Python>>正文


Python PngImagePlugin.PngInfo方法代码示例

本文整理汇总了Python中PIL.PngImagePlugin.PngInfo方法的典型用法代码示例。如果您正苦于以下问题:Python PngImagePlugin.PngInfo方法的具体用法?Python PngImagePlugin.PngInfo怎么用?Python PngImagePlugin.PngInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PIL.PngImagePlugin的用法示例。


在下文中一共展示了PngImagePlugin.PngInfo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_roundtrip_itxt

# 需要导入模块: from PIL import PngImagePlugin [as 别名]
# 或者: from PIL.PngImagePlugin import PngInfo [as 别名]
def test_roundtrip_itxt(self):
        # Check iTXt roundtripping

        im = Image.new("RGB", (32, 32))
        info = PngImagePlugin.PngInfo()
        info.add_itxt("spam", "Eggs", "en", "Spam")
        info.add_text("eggs", PngImagePlugin.iTXt("Spam", "en", "Eggs"),
                      zip=True)

        im = roundtrip(im, pnginfo=info)
        self.assertEqual(im.info, {"spam": "Eggs", "eggs": "Spam"})
        self.assertEqual(im.text, {"spam": "Eggs", "eggs": "Spam"})
        self.assertEqual(im.text["spam"].lang, "en")
        self.assertEqual(im.text["spam"].tkey, "Spam")
        self.assertEqual(im.text["eggs"].lang, "en")
        self.assertEqual(im.text["eggs"].tkey, "Eggs") 
开发者ID:holzschu,项目名称:python3_ios,代码行数:18,代码来源:test_file_png.py

示例2: test_unicode_text

# 需要导入模块: from PIL import PngImagePlugin [as 别名]
# 或者: from PIL.PngImagePlugin import PngInfo [as 别名]
def test_unicode_text(self):
        # Check preservation of non-ASCII characters on Python 3
        # This cannot really be meaningfully tested on Python 2,
        # since it didn't preserve charsets to begin with.

        def rt_text(value):
            im = Image.new("RGB", (32, 32))
            info = PngImagePlugin.PngInfo()
            info.add_text("Text", value)
            im = roundtrip(im, pnginfo=info)
            self.assertEqual(im.info, {"Text": value})

        if py3:
            rt_text(" Aa" + chr(0xa0) + chr(0xc4) + chr(0xff))  # Latin1
            rt_text(chr(0x400) + chr(0x472) + chr(0x4ff))       # Cyrillic
            rt_text(chr(0x4e00) + chr(0x66f0) +                 # CJK
                    chr(0x9fba) + chr(0x3042) + chr(0xac00))
            rt_text("A" + chr(0xc4) + chr(0x472) + chr(0x3042))  # Combined 
开发者ID:holzschu,项目名称:python3_ios,代码行数:20,代码来源:test_file_png.py

示例3: test_dos_total_memory

# 需要导入模块: from PIL import PngImagePlugin [as 别名]
# 或者: from PIL.PngImagePlugin import PngInfo [as 别名]
def test_dos_total_memory(self):
        im = Image.new('L', (1, 1))
        compressed_data = zlib.compress(b'a'*1024*1023)

        info = PngImagePlugin.PngInfo()

        for x in range(64):
            info.add_text('t%s' % x, compressed_data, zip=True)
            info.add_itxt('i%s' % x, compressed_data, zip=True)

        b = BytesIO()
        im.save(b, 'PNG', pnginfo=info)
        b.seek(0)

        try:
            im2 = Image.open(b)
        except ValueError as msg:
            self.assertIn("Too much memory", msg)
            return

        total_len = 0
        for txt in im2.text.values():
            total_len += len(txt)
        self.assertLess(total_len, 64*1024*1024,
                        "Total text chunks greater than 64M") 
开发者ID:holzschu,项目名称:python3_ios,代码行数:27,代码来源:check_png_dos.py

示例4: test_roundtrip_text

# 需要导入模块: from PIL import PngImagePlugin [as 别名]
# 或者: from PIL.PngImagePlugin import PngInfo [as 别名]
def test_roundtrip_text(self):
        # Check text roundtripping

        im = Image.open(TEST_PNG_FILE)

        info = PngImagePlugin.PngInfo()
        info.add_text("TXT", "VALUE")
        info.add_text("ZIP", "VALUE", zip=True)

        im = roundtrip(im, pnginfo=info)
        self.assertEqual(im.info, {'TXT': 'VALUE', 'ZIP': 'VALUE'})
        self.assertEqual(im.text, {'TXT': 'VALUE', 'ZIP': 'VALUE'}) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:14,代码来源:test_file_png.py

示例5: test_nonunicode_text

# 需要导入模块: from PIL import PngImagePlugin [as 别名]
# 或者: from PIL.PngImagePlugin import PngInfo [as 别名]
def test_nonunicode_text(self):
        # Check so that non-Unicode text is saved as a tEXt rather than iTXt

        im = Image.new("RGB", (32, 32))
        info = PngImagePlugin.PngInfo()
        info.add_text("Text", "Ascii")
        im = roundtrip(im, pnginfo=info)
        self.assertIsInstance(im.info["Text"], str) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:10,代码来源:test_file_png.py

示例6: pngsave

# 需要导入模块: from PIL import PngImagePlugin [as 别名]
# 或者: from PIL.PngImagePlugin import PngInfo [as 别名]
def pngsave(A, file, info={}):
    """
        wrapper around PIL 1.1.7 Image.save to preserve PNG metadata
        based on public domain script by Nick Galbreath                                                                                                        

        http://blog.modp.com/2007/08/python-pil-and-png-metadata-take-2.html                                                                 
    """
    from PIL import Image, PngImagePlugin
    im = Image.fromarray(256.0*A).convert('RGB')
    reserved = ('interlace', 'gamma', 'dpi', 'transparency', 'aspect')
    meta = PngImagePlugin.PngInfo()
    for k,v in _iteritems(info):
        if k in reserved: continue
        meta.add_text(k, v, 0)
    im.save(file, "PNG", pnginfo=meta) 
开发者ID:jahuth,项目名称:convis,代码行数:17,代码来源:png.py

示例7: png_client

# 需要导入模块: from PIL import PngImagePlugin [as 别名]
# 或者: from PIL.PngImagePlugin import PngInfo [as 别名]
def png_client(images,info={},port=10000,host='localhost',compress_level=0,resize=(1.0,1.0)):
    if len(images.shape) == 2:
        images = [images]
    # Create a TCP/IP socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    # Connect the socket to the port where the server is listening
    server_address = (host, port)
    sock.connect(server_address)
    try:
        for A in images:
            im = Image.fromarray(256.0*A).convert('RGB')
            if resize != (1.0,1.0) and resize is not None:
                if not type(resize) == tuple:
                    resize = (resize,resize)
                im = im.resize((int(resize[0]*im.size[0]), int(resize[1]*im.size[1])), PIL.Image.ANTIALIAS)
            output = StringIO.StringIO()
            meta = PngImagePlugin.PngInfo()
            reserved = ('interlace', 'gamma', 'dpi', 'transparency', 'aspect')
            for k,v in _iteritems(info):
                if k in reserved:
                    continue
                meta.add_text(str(k), str(v), 0)
            im.save(output, format="PNG", pnginfo=meta, compress_level=compress_level)
            message = output.getvalue()
            output.close()
            sock.sendall(message)
    finally:
        sock.close() 
开发者ID:jahuth,项目名称:convis,代码行数:31,代码来源:png.py

示例8: save_png_with_metadata

# 需要导入模块: from PIL import PngImagePlugin [as 别名]
# 或者: from PIL.PngImagePlugin import PngInfo [as 别名]
def save_png_with_metadata(fig, filename, fig_kwds, kwds):
    """ Save a matplotlib figure to a png with metadata
    """
    from PIL import Image, PngImagePlugin
    fig.savefig(filename, **fig_kwds)

    im = Image.open(filename)
    meta = PngImagePlugin.PngInfo()

    for key in kwds:
        meta.add_text(str(key), str(kwds[key]))

    im.save(filename, "png", pnginfo=meta) 
开发者ID:gwastro,项目名称:pycbc,代码行数:15,代码来源:metadata.py


注:本文中的PIL.PngImagePlugin.PngInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。