本文整理汇总了Python中mapproxy.platform.image.Image.blend方法的典型用法代码示例。如果您正苦于以下问题:Python Image.blend方法的具体用法?Python Image.blend怎么用?Python Image.blend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mapproxy.platform.image.Image
的用法示例。
在下文中一共展示了Image.blend方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: merge
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import blend [as 别名]
def merge(self, image_opts, size=None, bbox=None, bbox_srs=None, coverage=None):
"""
Merge the layers. If the format is not 'png' just return the last image.
:param format: The image format for the result.
:param size: The size for the merged output.
:rtype: `ImageSource`
"""
if not self.layers:
return BlankImageSource(size=size, image_opts=image_opts, cacheable=True)
if len(self.layers) == 1:
layer_img, layer = self.layers[0]
layer_opts = layer_img.image_opts
if (((layer_opts and not layer_opts.transparent) or image_opts.transparent)
and (not size or size == layer_img.size)
and (not layer or not layer.coverage or not layer.coverage.clip)
and not coverage):
# layer is opaque, no need to make transparent or add bgcolor
return layer_img
if size is None:
size = self.layers[0][0].size
cacheable = self.cacheable
result = create_image(size, image_opts)
for layer_img, layer in self.layers:
if not layer_img.cacheable:
cacheable = False
img = layer_img.as_image()
layer_image_opts = layer_img.image_opts
if layer and layer.coverage and layer.coverage.clip:
img = mask_image(img, bbox, bbox_srs, layer.coverage)
if (layer_image_opts and layer_image_opts.opacity is not None
and layer_image_opts.opacity < 1.0):
img = img.convert(result.mode)
result = Image.blend(result, img, layer_image_opts.opacity)
else:
if img.mode == 'RGBA':
# paste w transparency mask from layer
result.paste(img, (0, 0), img)
else:
result.paste(img, (0, 0))
# apply global clip coverage
if coverage:
bg = create_image(size, image_opts)
mask = mask_image(result, bbox, bbox_srs, coverage)
bg.paste(result, (0, 0), mask)
result = bg
return ImageSource(result, size=size, image_opts=image_opts, cacheable=cacheable)
示例2: merge
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import blend [as 别名]
def merge(self, image_opts, size=None, bbox=None, bbox_srs=None, coverage=None):
"""
Merge the layers. If the format is not 'png' just return the last image.
:param format: The image format for the result.
:param size: The size for the merged output.
:rtype: `ImageSource`
"""
if not self.layers:
return BlankImageSource(size=size, image_opts=image_opts, cacheable=True)
if len(self.layers) == 1:
layer_img, layer = self.layers[0]
layer_opts = layer_img.image_opts
if (((layer_opts and not layer_opts.transparent) or image_opts.transparent)
and (not size or size == layer_img.size)
and (not layer or not layer.coverage or not layer.coverage.clip)
and not coverage):
# layer is opaque, no need to make transparent or add bgcolor
return layer_img
if size is None:
size = self.layers[0][0].size
cacheable = self.cacheable
result = create_image(size, image_opts)
for layer_img, layer in self.layers:
if not layer_img.cacheable:
cacheable = False
img = layer_img.as_image()
layer_image_opts = layer_img.image_opts
if layer_image_opts is None:
opacity = None
else:
opacity = layer_image_opts.opacity
if layer and layer.coverage and layer.coverage.clip:
img = mask_image(img, bbox, bbox_srs, layer.coverage)
if result.mode != 'RGBA':
merge_composite = False
else:
merge_composite = has_alpha_composite_support()
if merge_composite:
if opacity is not None and opacity < 1.0:
# fade-out img to add opacity value
img = img.convert("RGBA")
alpha = img.split()[3]
alpha = ImageChops.multiply(
alpha,
ImageChops.constant(alpha, 255 * opacity)
)
img.putalpha(alpha)
if img.mode == 'RGB':
result.paste(img, (0, 0))
else:
# assume paletted images have transparency
if img.mode == 'P':
img = img.convert('RGBA')
result = Image.alpha_composite(result, img)
else:
if opacity is not None and opacity < 1.0:
img = img.convert(result.mode)
result = Image.blend(result, img, layer_image_opts.opacity)
elif img.mode == 'RGBA' or img.mode == 'P':
# assume paletted images have transparency
if img.mode == 'P':
img = img.convert('RGBA')
# paste w transparency mask from layer
result.paste(img, (0, 0), img)
else:
result.paste(img, (0, 0))
# apply global clip coverage
if coverage:
bg = create_image(size, image_opts)
mask = mask_image(result, bbox, bbox_srs, coverage)
bg.paste(result, (0, 0), mask)
result = bg
return ImageSource(result, size=size, image_opts=image_opts, cacheable=cacheable)