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


Python Image.register_extension方法代码示例

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


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

示例1: load

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
		self.mode = 'RGBA'
		self.size = self.icns.bestsize()
		self.info['sizes'] = self.icns.itersizes()
		# Just use this to see if it's loaded or not yet.
		self.tile = ('',)

	def load(self):
		Image.Image.load(self)
		if not self.tile:
			return
		self.load_prepare()
		# This is likely NOT the best way to do it, but whatever.
		im = self.icns.getimage(self.size)
		self.im = im.im
		self.mode = im.mode
		self.size = im.size
		self.fp = None
		self.icns = None
		self.tile = ()
		self.load_end()


Image.register_open("ICNS", IcnsImageFile, lambda x: x[:4] == 'icns')
Image.register_extension("ICNS", '.icns')

if __name__ == '__main__':
	import os, sys
	im = Image.open(open(sys.argv[1], "rb"))
	im.save("out.png")
	os.startfile("out.png")
开发者ID:TheArchives,项目名称:blockBox,代码行数:32,代码来源:IcnsImagePlugin.py

示例2: _accept

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
		if not _accept(self.fp.read(8)):
			raise SyntaxError("Not a GRIB file")

		self.fp.seek(offset)

		# make something up
		self.mode = "F"
		self.size = 1, 1

		loader = self._load()
		if loader:
			loader.open(self)

	def _load(self):
		return _handler

def _save(im, fp, filename):
	if _handler is None or not hasattr("_handler", "save"):
		raise IOError("GRIB save handler not installed")
	_handler.save(im, fp, filename)


# --------------------------------------------------------------------
# Registry

Image.register_open(GribStubImageFile.format, GribStubImageFile, _accept)
Image.register_save(GribStubImageFile.format, _save)

Image.register_extension(GribStubImageFile.format, ".grib")
开发者ID:TheArchives,项目名称:blockBox,代码行数:31,代码来源:GribStubImagePlugin.py

示例3: load_read

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
		self.mode = "P"
		self.palette = ImagePalette.raw("RGB", string.join(palette, ""))

		self.tile = [("raw", (0, 0)+self.size, self.fp.tell(), ("P", 0, 1))]

	def load_read(self, bytes):

		#
		# load all image data in one chunk

		xsize, ysize = self.size

		s = [None] * ysize

		for i in range(ysize):
			s[i] = string.ljust(self.fp.readline()[1:xsize+1], xsize)

		self.fp = None

		return string.join(s, "")

#
# Registry

Image.register_open("XPM", XpmImageFile, _accept)

Image.register_extension("XPM", ".xpm")

Image.register_mime("XPM", "image/xpm")
开发者ID:TheArchives,项目名称:blockBox,代码行数:31,代码来源:XpmImagePlugin.py

示例4: ord

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
			if not m:
				m = s
			elif ord(s[0]) > ord(m[0]) and ord(s[1]) > ord(m[1]):
				m = s
			#print "width", ord(s[0])
			#print "height", ord(s[1])
			#print "colors", ord(s[2])
			#print "reserved", ord(s[3])
			#print "planes", i16(s[4:])
			#print "bitcount", i16(s[6:])
			#print "bytes", i32(s[8:])
			#print "offset", i32(s[12:])

		# load as bitmap
		self._bitmap(i32(m[12:]))

		# patch up the bitmap height
		self.size = self.size[0], self.size[1]/2
		d, e, o, a = self.tile[0]
		self.tile[0] = d, (0,0)+self.size, o, a

		return


#
# --------------------------------------------------------------------

Image.register_open("ICO", IcoImageFile, _accept)

Image.register_extension("ICO", ".ico")
开发者ID:TheArchives,项目名称:blockBox,代码行数:32,代码来源:IcoImagePlugin.py

示例5: _load

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
            # include SIMPLE, BITPIX, NAXIS, etc.

        self.fp.seek(offset)

        # make something up
        self.mode = "F"
        self.size = 1, 1

        loader = self._load()
        if loader:
            loader.open(self)

    def _load(self):
        return _handler


def _save(im, fp, filename):
    if _handler is None or not hasattr("_handler", "save"):
        raise IOError("FITS save handler not installed")
    _handler.save(im, fp, filename)


# --------------------------------------------------------------------
# Registry

Image.register_open(FITSStubImageFile.format, FITSStubImageFile, _accept)
Image.register_save(FITSStubImageFile.format, _save)

Image.register_extension(FITSStubImageFile.format, ".fit")
Image.register_extension(FITSStubImageFile.format, ".fits")
开发者ID:katerberg-zz,项目名称:blockBox,代码行数:32,代码来源:FitsStubImagePlugin.py

示例6: _save

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
			self.tile = [("xbm", (0, 0)+self.size, m.end(), None)]


def _save(im, fp, filename):

	if im.mode != "1":
		raise IOError, "cannot write mode %s as XBM" % im.mode

	fp.write("#define im_width %d\n" % im.size[0])
	fp.write("#define im_height %d\n" % im.size[1])

	hotspot = im.encoderinfo.get("hotspot")
	if hotspot:
		fp.write("#define im_x_hot %d\n" % hotspot[0])
		fp.write("#define im_y_hot %d\n" % hotspot[1])

	fp.write("static char im_bits[] = {\n")

	ImageFile._save(im, fp, [("xbm", (0,0)+im.size, 0, None)])

	fp.write("};\n")


Image.register_open("XBM", XbmImageFile, _accept)
Image.register_save("XBM", _save)

Image.register_extension("XBM", ".xbm")

Image.register_mime("XBM", "image/xbm")
开发者ID:TheArchives,项目名称:blockBox,代码行数:31,代码来源:XbmImagePlugin.py

示例7: draft

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
		self.mode = "RGB"
		self.size = 768, 512 # FIXME: not correct for rotated images!
		self.tile = [("pcd", (0,0)+self.size, 96*2048, None)]

	def draft(self, mode, size):

		if len(self.tile) != 1:
			return

		d, e, o, a = self.tile[0]

		if size:
			scale = max(self.size[0] / size[0], self.size[1] / size[1])
			for s, o in [(4,0*2048), (2,0*2048), (1,96*2048)]:
				if scale >= s:
					break
			# e = e[0], e[1], (e[2]-e[0]+s-1)/s+e[0], (e[3]-e[1]+s-1)/s+e[1]
			# self.size = ((self.size[0]+s-1)/s, (self.size[1]+s-1)/s)

		self.tile = [(d, e, o, a)]

		return self

#
# registry

Image.register_open("PCD", PcdImageFile)

Image.register_extension("PCD", ".pcd")
开发者ID:TheArchives,项目名称:blockBox,代码行数:31,代码来源:PcdImagePlugin.py

示例8: i32

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
			self.mode, rawmode = "1", "1;I"
		elif depth == 8:
			self.mode = rawmode = "L"
		elif depth == 24:
			self.mode, rawmode = "RGB", "BGR"
		else:
			raise SyntaxError, "unsupported mode"

		compression = i32(s[20:24])

		if i32(s[24:28]) != 0:
			length = i32(s[28:32])
			offset = offset + length
			self.palette = ImagePalette.raw("RGB;L", self.fp.read(length))
			if self.mode == "L":
				self.mode = rawmode = "P"

		stride = (((self.size[0] * depth + 7) / 8) + 3) & (~3)

		if compression == 1:
			self.tile = [("raw", (0,0)+self.size, offset, (rawmode, stride))]
		elif compression == 2:
			self.tile = [("sun_rle", (0,0)+self.size, offset, rawmode)]

#
# registry

Image.register_open("SUN", SunImageFile, _accept)

Image.register_extension("SUN", ".ras")
开发者ID:TheArchives,项目名称:blockBox,代码行数:32,代码来源:SunImagePlugin.py

示例9: MpegImageFile

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
##
# Image plugin for MPEG streams.  This plugin can identify a stream,
# but it cannot read it.

class MpegImageFile(ImageFile.ImageFile):

	format = "MPEG"
	format_description = "MPEG"

	def _open(self):

		s = BitStream(self.fp)

		if s.read(32) != 0x1B3:
			raise SyntaxError, "not an MPEG file"

		self.mode = "RGB"
		self.size = s.read(12), s.read(12)


# --------------------------------------------------------------------
# Registry stuff

Image.register_open("MPEG", MpegImageFile)

Image.register_extension("MPEG", ".mpg")
Image.register_extension("MPEG", ".mpeg")

Image.register_mime("MPEG", "video/mpeg")
开发者ID:TheArchives,项目名称:blockBox,代码行数:31,代码来源:MpegImagePlugin.py

示例10: chr

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
	orientation = im.info.get("orientation", -1)
	if orientation > 0:
		flags = flags | 0x20

	fp.write("\000" +
			 chr(colormaptype) +
			 chr(imagetype) +
			 o16(colormapfirst) +
			 o16(colormaplength) +
			 chr(colormapentry) +
			 o16(0) +
			 o16(0) +
			 o16(im.size[0]) +
			 o16(im.size[1]) +
			 chr(bits) +
			 chr(flags))

	if colormaptype:
		fp.write(im.im.getpalette("RGB", "BGR"))

	ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, 0, orientation))])

#
# --------------------------------------------------------------------
# Registry

Image.register_open("TGA", TgaImageFile, _accept)
Image.register_save("TGA", _save)

Image.register_extension("TGA", ".tga")
开发者ID:TheArchives,项目名称:blockBox,代码行数:32,代码来源:TgaImagePlugin.py

示例11: i32

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
		if frame != self.frame + 1:
			raise ValueError, "cannot seek to frame %d" % frame
		self.frame = frame

		# move to next frame
		self.fp = self.__fp
		self.fp.seek(self.__offset)

		s = self.fp.read(4)
		if not s:
			raise EOFError

		framesize = i32(s)

		self.decodermaxblock = framesize
		self.tile = [("fli", (0,0)+self.size, self.__offset, None)]

		self.__offset = self.__offset + framesize

	def tell(self):

		return self.frame

#
# registry

Image.register_open("FLI", FliImageFile, _accept)

Image.register_extension("FLI", ".fli")
Image.register_extension("FLI", ".flc")
开发者ID:TheArchives,项目名称:blockBox,代码行数:32,代码来源:FliImagePlugin.py

示例12: SyntaxError

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
				self.info["dpi"] = xdpi, ydpi

		else:
			raise SyntaxError("Unsupported file format")

		self.mode = "RGB"
		self.size = size

		loader = self._load()
		if loader:
			loader.open(self)

	def _load(self):
		return _handler


def _save(im, fp, filename):
	if _handler is None or not hasattr("_handler", "save"):
		raise IOError("WMF save handler not installed")
	_handler.save(im, fp, filename)

#
# --------------------------------------------------------------------
# Registry stuff

Image.register_open(WmfStubImageFile.format, WmfStubImageFile, _accept)
Image.register_save(WmfStubImageFile.format, _save)

Image.register_extension(WmfStubImageFile.format, ".wmf")
Image.register_extension(WmfStubImageFile.format, ".emf")
开发者ID:TheArchives,项目名称:blockBox,代码行数:32,代码来源:WmfImagePlugin.py

示例13: getiptcinfo

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
			try:
				# fast
				self.im = Image.core.open_ppm(outfile)
			except:
				# slightly slower
				im = Image.open(outfile)
				im.load()
				self.im = im.im
		finally:
			try: os.unlink(outfile)
			except: pass


Image.register_open("IPTC", IptcImageFile)

Image.register_extension("IPTC", ".iim")

##
# Get IPTC information from TIFF, JPEG, or IPTC file.
#
# @param im An image containing IPTC data.
# @return A dictionary containing IPTC information, or None if
#	 no IPTC information block was found.

def getiptcinfo(im):

	import TiffImagePlugin, JpegImagePlugin
	import StringIO

	data = None
开发者ID:TheArchives,项目名称:blockBox,代码行数:32,代码来源:IptcImagePlugin.py

示例14: range

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
	fp.write(o16b(offset))
	fp.write(chr(transparent_index))
	fp.write(chr(compression_type))
	fp.write(o16b(0))   # reserved by Palm

	# now write colormap if necessary

	if colormapsize > 0:
		fp.write(o16b(256))
		for i in range(256):
			fp.write(chr(i))
			if colormapmode == 'RGB':
				fp.write(chr(colormap[3 * i]) + chr(colormap[3 * i + 1]) + chr(colormap[3 * i + 2]))
			elif colormapmode == 'RGBA':
				fp.write(chr(colormap[4 * i]) + chr(colormap[4 * i + 1]) + chr(colormap[4 * i + 2]))

	# now convert data to raw form
	ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, rowbytes, 1))])

	fp.flush()


#
# --------------------------------------------------------------------

Image.register_save("Palm", _save)

Image.register_extension("Palm", ".palm")

Image.register_mime("Palm", "image/palm")
开发者ID:TheArchives,项目名称:blockBox,代码行数:32,代码来源:PalmImagePlugin.py

示例15: _accept

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_extension [as 别名]
        if not _accept(self.fp.read(8)):
            raise SyntaxError("Not a BUFR file")

        self.fp.seek(offset)

        # make something up
        self.mode = "F"
        self.size = 1, 1

        loader = self._load()
        if loader:
            loader.open(self)

    def _load(self):
        return _handler


def _save(im, fp, filename):
    if _handler is None or not hasattr("_handler", "save"):
        raise IOError("BUFR save handler not installed")
    _handler.save(im, fp, filename)


# --------------------------------------------------------------------
# Registry

Image.register_open(BufrStubImageFile.format, BufrStubImageFile, _accept)
Image.register_save(BufrStubImageFile.format, _save)

Image.register_extension(BufrStubImageFile.format, ".bufr")
开发者ID:katerberg-zz,项目名称:blockBox,代码行数:32,代码来源:BufrStubImagePlugin.py


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