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


Python pil.Image类代码示例

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


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

示例1: setink

	def setink(self, ink):
		# compatibility
		if warnings:
			warnings.warn(
				"'setink' is deprecated; use keyword arguments instead",
				DeprecationWarning, stacklevel=2
				)
		if Image.isStringType(ink):
			ink = ImageColor.getcolor(ink, self.mode)
		if self.palette and not Image.isNumberType(ink):
			ink = self.palette.getcolor(ink)
		self.ink = self.draw.draw_ink(ink, self.mode)
开发者ID:TheArchives,项目名称:blockBox,代码行数:12,代码来源:ImageDraw.py

示例2: open

def open(filename):
	# FIXME: modify to return a WalImageFile instance instead of
	# plain Image object ?

	if hasattr(filename, "read"):
		fp = filename
	else:
		import __builtin__
		fp = __builtin__.open(filename, "rb")

	# read header fields
	header = fp.read(32+24+32+12)
	size = i32(header, 32), i32(header, 36)
	offset = i32(header, 40)

	# load pixel data
	fp.seek(offset)

	im = Image.fromstring("P", size, fp.read(size[0] * size[1]))
	im.putpalette(quake2palette)

	im.format = "WAL"
	im.format_description = "Quake2 Texture"

	# strings are null-terminated
	im.info["name"] = header[:32].split("\0", 1)[0]
	next_name = header[56:56+32].split("\0", 1)[0]
	if next_name:
		im.info["next_name"] = next_name

	return im
开发者ID:TheArchives,项目名称:blockBox,代码行数:31,代码来源:WalImageFile.py

示例3: grabclipboard

def grabclipboard():
	debug = 0 # temporary interface
	data = Image.core.grabclipboard(debug)
	if Image.isStringType(data):
		import BmpImagePlugin, StringIO
		return BmpImagePlugin.DibImageFile(StringIO.StringIO(data))
	return data
开发者ID:TheArchives,项目名称:blockBox,代码行数:7,代码来源:ImageGrab.py

示例4: __fixup

	def __fixup(self, im1):
		# convert image to suitable mode
		if isinstance(im1, _Operand):
			# argument was an image.
			if im1.im.mode in ("1", "L"):
				return im1.im.convert("I")
			elif im1.im.mode in ("I", "F"):
				return im1.im
			else:
				raise ValueError, "unsupported mode: %s" % im1.im.mode
		else:
			# argument was a constant
			if _isconstant(im1) and self.im.mode in ("1", "L", "I"):
				return Image.new("I", self.im.size, im1)
			else:
				return Image.new("F", self.im.size, im1)
开发者ID:TheArchives,项目名称:blockBox,代码行数:16,代码来源:ImageMath.py

示例5: load

		def load(self, im):
			im.fp.seek(0) # rewind
			return Image.fromstring(
				"RGB", im.size,
				Image.core.drawwmf(im.fp.read(), im.size, self.bbox),
				"raw", "BGR", (im.size[0]*3 + 3) & -4, -1
				)
开发者ID:TheArchives,项目名称:blockBox,代码行数:7,代码来源:WmfImagePlugin.py

示例6: __init__

	def __init__(self, im):

		data = None
		colortable = None

		# handle filename, if given instead of image name
		if hasattr(im, "toUtf8"):
			# FIXME - is this really the best way to do this?
			im = unicode(im.toUtf8(), "utf-8")
		if Image.isStringType(im):
			im = Image.open(im)

		if im.mode == "1":
			format = QImage.Format_Mono
		elif im.mode == "L":
			format = QImage.Format_Indexed8
			colortable = []
			for i in range(256):
				colortable.append(rgb(i, i, i))
		elif im.mode == "P":
			format = QImage.Format_Indexed8
			colortable = []
			palette = im.getpalette()
			for i in range(0, len(palette), 3):
				colortable.append(rgb(*palette[i:i+3]))
		elif im.mode == "RGB":
			data = im.tostring("raw", "BGRX")
			format = QImage.Format_RGB32
		elif im.mode == "RGBA":
			try:
				data = im.tostring("raw", "BGRA")
			except SystemError:
				# workaround for earlier versions
				r, g, b, a = im.split()
				im = Image.merge("RGBA", (b, g, r, a))
			format = QImage.Format_ARGB32
		else:
			raise ValueError("unsupported image mode %r" % im.mode)

		# must keep a reference, or Qt will crash!
		self.__data = data or im.tostring()

		QImage.__init__(self, self.__data, im.size[0], im.size[1], format)

		if colortable:
			self.setColorTable(colortable)
开发者ID:TheArchives,项目名称:blockBox,代码行数:46,代码来源:ImageQt.py

示例7: __init__

	def __init__(self, profile):
		# accepts a string (filename), a file-like object, or a low-level
		# profile object
		if Image.isStringType(profile):
			self._set(core.profile_open(profile), profile)
		elif hasattr(profile, "read"):
			self._set(core.profile_fromstring(profile.read()))
		else:
			self._set(profile) # assume it's already a profile
开发者ID:TheArchives,项目名称:blockBox,代码行数:9,代码来源:ImageCms.py

示例8: load_path

def load_path(filename):
	"Load a font file, searching along the Python path."
	for dir in sys.path:
		if Image.isDirectory(dir):
			try:
				return load(os.path.join(dir, filename))
			except IOError:
				pass
	raise IOError("cannot find font file")
开发者ID:TheArchives,项目名称:blockBox,代码行数:9,代码来源:ImageFont.py

示例9: grab

def grab(bbox=None):
	size, data = grabber()
	im = Image.fromstring(
		"RGB", size, data,
		# RGB, 32-bit line padding, origo in lower left corner
		"raw", "BGR", (size[0]*3 + 3) & -4, -1
		)
	if bbox:
		im = im.crop(bbox)
	return im
开发者ID:TheArchives,项目名称:blockBox,代码行数:10,代码来源:ImageGrab.py

示例10: build_prototype_image

def build_prototype_image():
	image = Image.new("L", (1,len(_Palm8BitColormapValues),))
	image.putdata(range(len(_Palm8BitColormapValues)))
	palettedata = ()
	for i in range(len(_Palm8BitColormapValues)):
		palettedata = palettedata + _Palm8BitColormapValues[i]
	for i in range(256 - len(_Palm8BitColormapValues)):
		palettedata = palettedata + (0, 0, 0)
	image.putpalette(palettedata)
	return image
开发者ID:TheArchives,项目名称:blockBox,代码行数:10,代码来源:PalmImagePlugin.py

示例11: _getink

	def _getink(self, ink, fill=None):
		if ink is None and fill is None:
			if self.fill:
				fill = self.ink
			else:
				ink = self.ink
		else:
			if ink is not None:
				if Image.isStringType(ink):
					ink = ImageColor.getcolor(ink, self.mode)
				if self.palette and not Image.isNumberType(ink):
					ink = self.palette.getcolor(ink)
				ink = self.draw.draw_ink(ink, self.mode)
			if fill is not None:
				if Image.isStringType(fill):
					fill = ImageColor.getcolor(fill, self.mode)
				if self.palette and not Image.isNumberType(fill):
					fill = self.palette.getcolor(fill)
				fill = self.draw.draw_ink(fill, self.mode)
		return ink, fill
开发者ID:TheArchives,项目名称:blockBox,代码行数:20,代码来源:ImageDraw.py

示例12: bdf_char

def bdf_char(f):

	# skip to STARTCHAR
	while 1:
		s = f.readline()
		if not s:
			return None
		if s[:9] == "STARTCHAR":
			break
	id = string.strip(s[9:])

	# load symbol properties
	props = {}
	while 1:
		s = f.readline()
		if not s or s[:6] == "BITMAP":
			break
		i = string.find(s, " ")
		props[s[:i]] = s[i+1:-1]

	# load bitmap
	bitmap = []
	while 1:
		s = f.readline()
		if not s or s[:7] == "ENDCHAR":
			break
		bitmap.append(s[:-1])
	bitmap = string.join(bitmap, "")

	[x, y, l, d] = map(int, string.split(props["BBX"]))
	[dx, dy] = map(int, string.split(props["DWIDTH"]))

	bbox = (dx, dy), (l, -d-y, x+l, -d), (0, 0, x, y)

	try:
		im = Image.fromstring("1", (x, y), bitmap, "hex", "1")
	except ValueError:
		# deal with zero-width characters
		im = Image.new("1", (x, y))

	return id, int(props["ENCODING"]), bbox, im
开发者ID:TheArchives,项目名称:blockBox,代码行数:41,代码来源:BdfFontFile.py

示例13: getcolor

def getcolor(color, mode):
	# same as getrgb, but converts the result to the given mode
	color = getrgb(color)
	if mode == "RGB":
		return color
	if mode == "RGBA":
		r, g, b = color
		return r, g, b, 255
	if Image.getmodebase(mode) == "L":
		r, g, b = color
		return (r*299 + g*587 + b*114)/1000
	return color
开发者ID:TheArchives,项目名称:blockBox,代码行数:12,代码来源:ImageColor.py

示例14: _save

def _save(im, fp, tile):
    "Helper to save image based on tile list"

    im.load()
    if not hasattr(im, "encoderconfig"):
        im.encoderconfig = ()
    tile.sort(_tilesort)
    # FIXME: make MAXBLOCK a configuration parameter
    bufsize = max(MAXBLOCK, im.size[0] * 4)  # see RawEncode.c
    try:
        fh = fp.fileno()
        fp.flush()
    except AttributeError:
        # compress to Python file-compatible object
        for e, b, o, a in tile:
            e = Image._getencoder(im.mode, e, a, im.encoderconfig)
            if o > 0:
                fp.seek(o, 0)
            e.setimage(im.im, b)
            while 1:
                l, s, d = e.encode(bufsize)
                fp.write(d)
                if s:
                    break
            if s < 0:
                raise IOError("encoder error %d when writing image file" % s)
    else:
        # slight speedup: compress to real file object
        for e, b, o, a in tile:
            e = Image._getencoder(im.mode, e, a, im.encoderconfig)
            if o > 0:
                fp.seek(o, 0)
            e.setimage(im.im, b)
            s = e.encode_to_file(fh, bufsize)
            if s < 0:
                raise IOError("encoder error %d when writing image file" % s)
    try:
        fp.flush()
    except:
        pass
开发者ID:katerberg-zz,项目名称:blockBox,代码行数:40,代码来源:ImageFile.py

示例15: __init__

	def __init__(self, image, size=None):
		if hasattr(image, "mode") and hasattr(image, "size"):
			mode = image.mode
			size = image.size
		else:
			mode = image
			image = None
		if mode not in ["1", "L", "P", "RGB"]:
			mode = Image.getmodebase(mode)
		self.image = Image.core.display(mode, size)
		self.mode = mode
		self.size = size
		if image:
			self.paste(image)
开发者ID:TheArchives,项目名称:blockBox,代码行数:14,代码来源:ImageWin.py


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