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


Python PIL.PngImagePlugin类代码示例

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


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

示例1: test_roundtrip_itxt

    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:BaeFlower,项目名称:Pillow,代码行数:15,代码来源:test_file_png.py

示例2: chunk

def chunk(cid, *data):
    file = BytesIO()
    PngImagePlugin.putchunk(*(file, cid) + data)
    return file.getvalue()
开发者ID:BaeFlower,项目名称:Pillow,代码行数:4,代码来源:test_file_png.py

示例3: test_getchunks

    def test_getchunks(self):
        im = hopper()

        chunks = PngImagePlugin.getchunks(im)
        self.assertEqual(len(chunks), 3)
开发者ID:wiredfool,项目名称:Pillow,代码行数:5,代码来源:test_file_png.py

示例4: load_icon

def load_icon(_imgPath, index=None):
	if isinstance(_imgPath, basestring):
		file = open(_imgPath, 'rb')

	try:
		header = struct.unpack('<3H', file.read(6))
	except:
		raise IOError('Not an ICO file')

	# Check magic
	try:
		if header[:2] != (0, 1):
			raise IOError('Not an ICO file')
	except:
		return loadPNG(_imgPath)

	# Collect icon directories
	directories = []
	for i in xrange(header[2]):
		directory = list(struct.unpack('<4B2H2I', file.read(16)))
		for j in xrange(3):
			if not directory[j]:
				directory[j] = 256

		directories.append(directory)

	if index is None:
		# Select best icon
		directory = max(directories, key=operator.itemgetter(slice(0, 3)))
	else:
		directory = directories[index]

	# Seek to the bitmap data
	file.seek(directory[7])

	prefix = file.read(16)
	file.seek(-16, 1)

	if PngImagePlugin._accept(prefix):
		# Windows Vista icon with PNG inside
		image = PngImagePlugin.PngImageFile(file)
	else:
		# Load XOR bitmap
		image = BmpImagePlugin.DibImageFile(file)
		if image.mode == 'RGBA':
			# Windows XP 32-bit color depth icon without AND bitmap
			pass
		else:
			# Patch up the bitmap height
			image.size = image.size[0], image.size[1] >> 1
			d, e, o, a = image.tile[0]
			image.tile[0] = d, (0, 0) + image.size, o, a

			# Calculate AND bitmap dimensions. See
			offset = o + a[1] * image.size[1]
			stride = ((image.size[0] + 31) >> 5) << 2
			size = stride * image.size[1]

			# Load AND bitmap
			file.seek(offset)
			string = file.read(size)
			mask = Image.frombytes('1', image.size, string, 'raw',
									('1;I', stride, -1))

			image = image.convert('RGBA')
			image.putalpha(mask)

	return image, image.size
开发者ID:pewsheen,项目名称:ico2xlsx,代码行数:68,代码来源:ico2xlsx_ui.py

示例5: load_icon

def load_icon(file, index=None):
    '''
    Load Windows ICO image.

    See http://en.wikipedia.org/w/index.php?oldid=264332061 for file format
    description.
    '''
    if isinstance(file, basestring):
        file = open(file, 'rb')

    header = struct.unpack('<3H', file.read(6))

    # Check magic
    if header[:2] != (0, 1):
        raise SyntaxError('Not an ICO file')

    # Collect icon directories
    directories = []
    for i in xrange(header[2]):
        directory = list(struct.unpack('<4B2H2I', file.read(16)))
        for j in xrange(3):
            if not directory[j]:
                directory[j] = 256

        directories.append(directory)

    if index is None:
        # Select best icon
        directory = max(directories, key=operator.itemgetter(slice(0, 3)))
    else:
        directory = directories[index]

    # Seek to the bitmap data
    file.seek(directory[7])

    prefix = file.read(16)
    file.seek(-16, 1)

    if PngImagePlugin._accept(prefix):
        # Windows Vista icon with PNG inside
        image = PngImagePlugin.PngImageFile(file)
    else:
        # Load XOR bitmap
        image = BmpImagePlugin.DibImageFile(file)
        if image.mode == 'RGBA':
            # Windows XP 32-bit color depth icon without AND bitmap
            pass
        else:
            # Patch up the bitmap height
            image.size = image.size[0], image.size[1] >> 1
            d, e, o, a = image.tile[0]
            image.tile[0] = d, (0, 0) + image.size, o, a

            # Calculate AND bitmap dimensions. See
            # http://en.wikipedia.org/w/index.php?oldid=264236948#Pixel_storage
            # for description
            offset = o + a[1] * image.size[1]
            stride = ((image.size[0] + 31) >> 5) << 2
            size = stride * image.size[1]

            # Load AND bitmap
            file.seek(offset)
            string = file.read(size)
            mask = Image.fromstring('1', image.size, string, 'raw',
                                    ('1;I', stride, -1))

            image = image.convert('RGBA')
            image.putalpha(mask)

    return image
开发者ID:CodeforEvolution,项目名称:miro,代码行数:70,代码来源:update-icons.py

示例6: max

            directories.append(directory)

        if index is None:
            # Select best icon
            directory = max(directories, key=operator.itemgetter(slice(0, 3)))
        else:
            directory = directories[index]

        # Seek to the bitmap data
        image_file.seek(directory[7])

        prefix = image_file.read(16)
        image_file.seek(-16, 1)

        if PngImagePlugin._accept(prefix):
            # Windows Vista icon with PNG inside
            try:
                image = PngImagePlugin.PngImageFile(image_file)
            except IOError:
                return
        else:
            # Load XOR bitmap
            try:
                image = BmpImagePlugin.DibImageFile(image_file)
            except IOError:
                return
            if image.mode == 'RGBA':
                # Windows XP 32-bit color depth icon without AND bitmap
                pass
            else:
开发者ID:carlchen0928,项目名称:rssEngine,代码行数:30,代码来源:icon_importer.py

示例7: IHDR

while True:
    s = fp.read(629)
    print s
    if not s:
        break
    p.feed(s)

im = p.close()

im.save("o2.png")

#im.show()

# chunky = png.PngStream(im)

chunks_are_us = png.getchunks(fp)



#for item in chunks_are_us:
    #print item[0]
#this returns these:
# IHDR (required)
# IDAT (image data chunk 1)
# IDAT (image data chunk 2)
# IEND (required)

#no itXt chunk or other metadata
#this works but is not informative
# for k,v in im.info.iteritems():
#     print k,v
开发者ID:OpenSorceress,项目名称:python-practice,代码行数:31,代码来源:oxygen.py


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