本文整理汇总了Python中mapproxy.platform.image.Image.new方法的典型用法代码示例。如果您正苦于以下问题:Python Image.new方法的具体用法?Python Image.new怎么用?Python Image.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mapproxy.platform.image.Image
的用法示例。
在下文中一共展示了Image.new方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_solid_merge
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def test_solid_merge(self):
img1 = ImageSource(Image.new('RGB', (10, 10), (255, 0, 255)))
img2 = ImageSource(Image.new('RGB', (10, 10), (0, 255, 255)))
result = merge_images([img1, img2], ImageOptions(transparent=False))
img = result.as_image()
eq_(img.getpixel((0, 0)), (0, 255, 255))
示例2: test_paletted_merge
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def test_paletted_merge(self):
if not hasattr(Image, 'FASTOCTREE'):
raise SkipTest()
# generate RGBA images with a transparent rectangle in the lower right
img1 = ImageSource(Image.new('RGBA', (50, 50), (0, 255, 0, 255))).as_image()
draw = ImageDraw.Draw(img1)
draw.rectangle((25, 25, 49, 49), fill=(0, 0, 0, 0))
paletted_img = quantize(img1, alpha=True)
assert img_has_transparency(paletted_img)
assert paletted_img.mode == 'P'
rgba_img = Image.new('RGBA', (50, 50), (255, 0, 0, 255))
draw = ImageDraw.Draw(rgba_img)
draw.rectangle((25, 25, 49, 49), fill=(0, 0, 0, 0))
img1 = ImageSource(paletted_img)
img2 = ImageSource(rgba_img)
# generate base image and merge the others above
img3 = ImageSource(Image.new('RGBA', (50, 50), (0, 0, 255, 255)))
result = merge_images([img3, img1, img2], ImageOptions(transparent=True))
img = result.as_image()
assert img.mode == 'RGBA'
eq_(img.getpixel((49, 49)), (0, 0, 255, 255))
eq_(img.getpixel((0, 0)), (255, 0, 0, 255))
示例3: test_composite_merge
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def test_composite_merge(self):
# http://stackoverflow.com/questions/3374878
if not hasattr(Image, 'alpha_composite'):
raise SkipTest()
img1 = Image.new('RGBA', size=(100, 100), color=(255, 0, 0, 255))
draw = ImageDraw.Draw(img1)
draw.rectangle((33, 0, 66, 100), fill=(255, 0, 0, 128))
draw.rectangle((67, 0, 100, 100), fill=(255, 0, 0, 0))
img1 = ImageSource(img1)
img2 = Image.new('RGBA', size =(100, 100), color=(0, 255, 0, 255))
draw = ImageDraw.Draw(img2)
draw.rectangle((0, 33, 100, 66), fill=(0, 255, 0, 128))
draw.rectangle((0, 67, 100, 100), fill=(0, 255, 0, 0))
img2 = ImageSource(img2)
result = merge_images([img2, img1], ImageOptions(merge='composite', transparent=True))
img = result.as_image()
eq_(img.mode, 'RGBA')
eq_(sorted(img.getcolors()), sorted([
(1089, (0, 255, 0, 255)),
(1089, (255, 255, 255, 0)),
(1122, (0, 255, 0, 128)),
(1122, (128, 126, 0, 255)),
(1122, (255, 0, 0, 128)),
(1156, (170, 84, 0, 191)),
(3300, (255, 0, 0, 255))]))
示例4: test_opacity_merge_mixed_modes
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def test_opacity_merge_mixed_modes(self):
img1 = ImageSource(Image.new('RGBA', (10, 10), (255, 0, 255, 255)))
img2 = ImageSource(Image.new('RGB', (10, 10), (0, 255, 255)).convert('P'),
image_opts=ImageOptions(opacity=0.5))
result = merge_images([img1, img2], ImageOptions(transparent=True))
img = result.as_image()
eq_(img.getpixel((0, 0)), (127, 127, 255, 255))
示例5: create_debug_img
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def create_debug_img(size, transparent=True):
if transparent:
img = Image.new("RGBA", size)
else:
img = Image.new("RGB", size, ImageColor.getrgb("#EEE"))
draw = ImageDraw.Draw(img)
draw_pattern(draw, size)
return img
示例6: test_opacity_merge_mixed_modes
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def test_opacity_merge_mixed_modes(self):
img1 = ImageSource(Image.new('RGBA', (10, 10), (255, 0, 255, 255)))
img2 = ImageSource(Image.new('RGB', (10, 10), (0, 255, 255)).convert('P'),
image_opts=ImageOptions(opacity=0.5))
result = merge_images([img1, img2], ImageOptions(transparent=True))
img = result.as_image()
assert_colors_equal(img, [
(10*10, (127, 127, 255, 255)),
])
示例7: create_image
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def create_image(size, color=None, mode=None):
if color is not None:
if isinstance(color, basestring):
if mode is None:
mode = 'RGB'
img = Image.new(mode, size, color=color)
else:
if mode is None:
mode = 'RGBA' if len(color) == 4 else 'RGB'
img = Image.new(mode, size, color=tuple(color))
else:
img = create_debug_img(size)
return img
示例8: test_concatenation
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def test_concatenation(self):
legends = []
img_1 = Image.new(mode='RGBA', size=(30,10), color="red")
img_2 = Image.new(mode='RGBA', size=(10,10), color="black")
img_3 = Image.new(mode='RGBA', size=(50,80), color="blue")
legends.append(ImageSource(img_1))
legends.append(ImageSource(img_2))
legends.append(ImageSource(img_3))
source = concat_legends(legends)
src_img = source.as_image()
assert src_img.getpixel((0,90)) == (255,0,0,255)
assert src_img.getpixel((0,80)) == (0,0,0,255)
assert src_img.getpixel((0,0)) == (0,0,255,255)
assert src_img.getpixel((49,99)) == (255,255,255,0)
assert is_png(source.as_buffer())
示例9: test_rgb
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def test_rgb(self):
if hasattr(Image, 'FASTOCTREE'):
img = Image.new('RGB', (10, 10))
assert not img_has_transparency(img)
img = quantize(img, alpha=False)
assert not img_has_transparency(img)
示例10: test_solid_paletted_image
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def test_solid_paletted_image(self):
img = Image.new('P', (100, 100), color=20)
palette = []
for i in range(256):
palette.extend((i, i//2, i%3))
img.putpalette(palette)
eq_(is_single_color_image(img), (20, 10, 2))
示例11: test_mask_partial_image_transparent
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def test_mask_partial_image_transparent(self):
img = ImageSource(Image.new('RGB', (100, 100), color=(100, 0, 200)),
image_opts=ImageOptions(transparent=True))
result = mask_image_source_from_coverage(img, [0, 0, 10, 10], SRS(4326), coverage([5, 5, 30, 30]))
eq_(result.as_image().getcolors(),
[(7500, (255, 255, 255, 0)), (2500, (100, 0, 200, 255))])
示例12: create_image
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def create_image(size, image_opts=None):
"""
Create a new image that is compatible with the given `image_opts`.
Takes into account mode, transparent, bgcolor.
"""
from mapproxy.platform.image import Image, ImageColor
if image_opts is None:
mode = 'RGB'
bgcolor = (255, 255, 255)
else:
mode = image_opts.mode
if mode in (None, 'P'):
if image_opts.transparent:
mode = 'RGBA'
else:
mode = 'RGB'
bgcolor = image_opts.bgcolor or (255, 255, 255)
if isinstance(bgcolor, basestring):
bgcolor = ImageColor.getrgb(bgcolor)
if image_opts.transparent and len(bgcolor) == 3:
bgcolor = bgcolor + (0, )
if image_opts.mode == 'I':
bgcolor = bgcolor[0]
return Image.new(mode, size, bgcolor)
示例13: test_mask_partial_image_bgcolor
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def test_mask_partial_image_bgcolor(self):
img = ImageSource(
Image.new("RGB", (100, 100), color=(100, 0, 200)), image_opts=ImageOptions(bgcolor=(200, 30, 120))
)
result = mask_image_source_from_coverage(img, [0, 0, 10, 10], SRS(4326), coverage([5, 5, 30, 30]))
eq_(result.as_image().getcolors(), [(7500, (200, 30, 120)), (2500, (100, 0, 200))])
示例14: test_one_point
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def test_one_point(self):
img = Image.new('RGB', (100, 100), color='#ff0000')
draw = ImageDraw.Draw(img)
draw.point((99, 99))
del draw
assert not is_single_color_image(img)
示例15: test_rbga
# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import new [as 别名]
def test_rbga(self):
if hasattr(Image, 'FASTOCTREE'):
img = Image.new('RGBA', (10, 10), (100, 200, 50, 255))
img.paste((255, 50, 50, 0), (3, 3, 7, 7))
assert img_has_transparency(img)
img = quantize(img, alpha=True)
assert img_has_transparency(img)