本文整理汇总了Python中mapproxy.platform.image.Image.eval方法的典型用法代码示例。如果您正苦于以下问题:Python Image.eval方法的具体用法?Python Image.eval怎么用?Python Image.eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mapproxy.platform.image.Image
的用法示例。
在下文中一共展示了Image.eval方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: quantize
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import eval [as 别名]
def quantize(img, colors=256, alpha=False, defaults=None, quantizer=None):
if hasattr(Image, 'FASTOCTREE') and quantizer in (None, 'fastoctree'):
if not alpha:
img = img.convert('RGB')
img = img.quantize(colors, Image.FASTOCTREE)
else:
if alpha and img.mode == 'RGBA':
img.load() # split might fail if image is not loaded
alpha = img.split()[3]
img = img.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=colors-1)
mask = Image.eval(alpha, lambda a: 255 if a <=128 else 0)
img.paste(255, mask)
if defaults is not None:
defaults['transparency'] = 255
else:
img = img.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=colors)
return img
示例2: _make_transparent
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import eval [as 别名]
def _make_transparent(img, color, tolerance=10):
img.load()
if img.mode == 'P':
img = img.convert('RGBA')
channels = img.split()
mask_channels = []
for ch, c in zip(channels, color):
# create bit mask for each matched color
low_c, high_c = c-tolerance, c+tolerance
mask_channels.append(Image.eval(ch, lambda x: 255 if low_c <= x <= high_c else 0))
# multiply channel bit masks to get a single mask
alpha = reduce(ImageChops.multiply, mask_channels)
# invert to get alpha channel
alpha = ImageChops.invert(alpha)
if len(channels) == 4:
# multiply with existing alpha
alpha = ImageChops.multiply(alpha, channels[-1])
img.putalpha(alpha)
return img