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


Python Image.new方法代码示例

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


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

示例1: __fixup

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import new [as 别名]
	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,代码行数:18,代码来源:ImageMath.py

示例2: build_prototype_image

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import new [as 别名]
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,代码行数:12,代码来源:PalmImagePlugin.py

示例3: apply

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import new [as 别名]
	def apply(self, op, im1, im2=None, mode=None):
		im1 = self.__fixup(im1)
		if im2 is None:
			# unary operation
			out = Image.new(mode or im1.mode, im1.size, None)
			im1.load()
			try:
				op = getattr(_imagingmath, op+"_"+im1.mode)
			except AttributeError:
				raise TypeError, "bad operand type for '%s'" % op
			_imagingmath.unop(op, out.im.id, im1.im.id)
		else:
			# binary operation
			im2 = self.__fixup(im2)
			if im1.mode != im2.mode:
				# convert both arguments to floating point
				if im1.mode != "F": im1 = im1.convert("F")
				if im2.mode != "F": im2 = im2.convert("F")
				if im1.mode != im2.mode:
					raise ValueError, "mode mismatch"
			if im1.size != im2.size:
				# crop both arguments to a common size
				size = (min(im1.size[0], im2.size[0]),
						min(im1.size[1], im2.size[1]))
				if im1.size != size: im1 = im1.crop((0, 0) + size)
				if im2.size != size: im2 = im2.crop((0, 0) + size)
				out = Image.new(mode or im1.mode, size, None)
			else:
				out = Image.new(mode or im1.mode, im1.size, None)
			im1.load(); im2.load()
			try:
				op = getattr(_imagingmath, op+"_"+im1.mode)
			except AttributeError:
				raise TypeError, "bad operand type for '%s'" % op
			_imagingmath.binop(op, out.im.id, im1.im.id, im2.im.id)
		return _Operand(out)
开发者ID:TheArchives,项目名称:blockBox,代码行数:38,代码来源:ImageMath.py

示例4: compile

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import new [as 别名]
	def compile(self):
		"Create metrics and bitmap"

		if self.bitmap:
			return

		# create bitmap large enough to hold all data
		h = w = maxwidth = 0
		lines = 1
		for glyph in self:
			if glyph:
				d, dst, src, im = glyph
				h = max(h, src[3] - src[1])
				w = w + (src[2] - src[0])
				if w > WIDTH:
					lines = lines + 1
					w = (src[2] - src[0])
				maxwidth = max(maxwidth, w)

		xsize = maxwidth
		ysize = lines * h

		if xsize == 0 and ysize == 0:
			return ""

		self.ysize = h

		# paste glyphs into bitmap
		self.bitmap = Image.new("1", (xsize, ysize))
		self.metrics = [None] * 256
		x = y = 0
		for i in range(256):
			glyph = self[i]
			if glyph:
				d, dst, src, im = glyph
				xx, yy = src[2] - src[0], src[3] - src[1]
				x0, y0 = x, y
				x = x + xx
				if x > WIDTH:
					x, y = 0, y + h
					x0, y0 = x, y
					x = xx
				s = src[0] + x0, src[1] + y0, src[2] + x0, src[3] + y0
				self.bitmap.paste(im.crop(src), s)
				# print chr(i), dst, s
				self.metrics[i] = d, dst, s
开发者ID:TheArchives,项目名称:blockBox,代码行数:48,代码来源:FontFile.py

示例5: bdf_char

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import new [as 别名]
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,代码行数:43,代码来源:BdfFontFile.py

示例6: _save

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import new [as 别名]
def _save(im, fp, filename):
	resolution = im.encoderinfo.get("resolution", 72.0)

	#
	# make sure image data is available
	im.load()

	xref = [0]*(5+1) # placeholders

	fp.write("%PDF-1.2\n")
	fp.write("% created by PIL PDF driver " + __version__ + "\n")

	#
	# Get image characteristics

	width, height = im.size

	# FIXME: Should replace ASCIIHexDecode with RunLengthDecode (packbits)
	# or LZWDecode (tiff/lzw compression).  Note that PDF 1.2 also supports
	# Flatedecode (zip compression).

	bits = 8
	params = None

	if im.mode == "1":
		filter = "/ASCIIHexDecode"
		colorspace = "/DeviceGray"
		procset = "/ImageB" # grayscale
		bits = 1
	elif im.mode == "L":
		filter = "/DCTDecode"
		# params = "<< /Predictor 15 /Columns %d >>" % (width-2)
		colorspace = "/DeviceGray"
		procset = "/ImageB" # grayscale
	elif im.mode == "P":
		filter = "/ASCIIHexDecode"
		colorspace = "[ /Indexed /DeviceRGB 255 <"
		palette = im.im.getpalette("RGB")
		for i in range(256):
			r = ord(palette[i*3])
			g = ord(palette[i*3+1])
			b = ord(palette[i*3+2])
			colorspace = colorspace + "%02x%02x%02x " % (r, g, b)
		colorspace = colorspace + "> ]"
		procset = "/ImageI" # indexed color
	elif im.mode == "RGB":
		filter = "/DCTDecode"
		colorspace = "/DeviceRGB"
		procset = "/ImageC" # color images
	elif im.mode == "CMYK":
		filter = "/DCTDecode"
		colorspace = "/DeviceCMYK"
		procset = "/ImageC" # color images
	else:
		raise ValueError("cannot save mode %s" % im.mode)

	#
	# catalogue

	xref[1] = fp.tell()
	_obj(fp, 1, Type = "/Catalog",
				Pages = "2 0 R")
	_endobj(fp)

	#
	# pages

	xref[2] = fp.tell()
	_obj(fp, 2, Type = "/Pages",
				Count = 1,
				Kids = "[4 0 R]")
	_endobj(fp)

	#
	# image

	op = StringIO.StringIO()

	if filter == "/ASCIIHexDecode":
		if bits == 1:
			# FIXME: the hex encoder doesn't support packed 1-bit
			# images; do things the hard way...
			data = im.tostring("raw", "1")
			im = Image.new("L", (len(data), 1), None)
			im.putdata(data)
		ImageFile._save(im, op, [("hex", (0,0)+im.size, 0, im.mode)])
	elif filter == "/DCTDecode":
		ImageFile._save(im, op, [("jpeg", (0,0)+im.size, 0, im.mode)])
	elif filter == "/FlateDecode":
		ImageFile._save(im, op, [("zip", (0,0)+im.size, 0, im.mode)])
	elif filter == "/RunLengthDecode":
		ImageFile._save(im, op, [("packbits", (0,0)+im.size, 0, im.mode)])
	else:
		raise ValueError("unsupported PDF filter (%s)" % filter)

	xref[3] = fp.tell()
	_obj(fp, 3, Type = "/XObject",
				Subtype = "/Image",
				Width = width, # * 72.0 / resolution,
				Height = height, # * 72.0 / resolution,
#.........这里部分代码省略.........
开发者ID:TheArchives,项目名称:blockBox,代码行数:103,代码来源:PdfImagePlugin.py

示例7: constant

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import new [as 别名]
def constant(image, value):
	"Fill a channel with a given grey level"

	return Image.new("L", image.size, value)
开发者ID:TheArchives,项目名称:blockBox,代码行数:6,代码来源:ImageChops.py

示例8: apply

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import new [as 别名]
	def apply(self, im, imOut=None):
		im.load()
		if imOut is None:
			imOut = Image.new(self.output_mode, im.size, None)
		result = self.transform.apply(im.im.id, imOut.im.id)
		return imOut
开发者ID:TheArchives,项目名称:blockBox,代码行数:8,代码来源:ImageCms.py

示例9: read_32

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import new [as 别名]
	return read_32(fobj, (start + 4, length - 4), (width, height))

def read_32(fobj, (start, length), size):
	"""
	Read a 32bit RGB icon resource.  Seems to be either uncompressed or
	an RLE packbits-like scheme.
	"""
	fobj.seek(start)
	sizesq = size[0] * size[1]
	if length == sizesq * 3:
		# uncompressed ("RGBRGBGB")
		indata = fobj.read(length)
		im = Image.frombuffer("RGB", size, indata, "raw", "RGB", 0, 1)
	else:
		# decode image
		im = Image.new("RGB", size, None)
		for band_ix in range(3):
			data = []
			bytesleft = sizesq
			while bytesleft > 0:
				byte = fobj.read(1)
				if not byte:
					break
				byte = ord(byte)
				if byte & 0x80:
					blocksize = byte - 125
					byte = fobj.read(1)
					for i in range(blocksize):
						data.append(byte)
				else:
					blocksize = byte + 1
开发者ID:TheArchives,项目名称:blockBox,代码行数:33,代码来源:IcnsImagePlugin.py

示例10: __init__

# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import new [as 别名]
	def __init__(self, image, size=None, color=None):
		if not hasattr(image, "im"):
			image = Image.new(image, size, color)
		self.draw = ImageDraw.Draw(image)
		self.image = image
		self.transform = None
开发者ID:TheArchives,项目名称:blockBox,代码行数:8,代码来源:ImageDraw2.py


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