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


Python Image.eval方法代码示例

本文整理汇总了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
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:20,代码来源:__init__.py

示例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
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:26,代码来源:__init__.py


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