本文整理汇总了Python中mapproxy.compat.image.Image类的典型用法代码示例。如果您正苦于以下问题:Python Image类的具体用法?Python Image怎么用?Python Image使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Image类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_solid_merge
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))
开发者ID:tjay,项目名称:mapproxy,代码行数:7,代码来源:test_image.py
示例2: test_paletted_merge
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))
开发者ID:tjay,项目名称:mapproxy,代码行数:27,代码来源:test_image.py
示例3: test_composite_merge
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(transparent=True))
img = result.as_image()
eq_(img.mode, 'RGBA')
assert_img_colors_eq(img, [
(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))])
开发者ID:tjay,项目名称:mapproxy,代码行数:28,代码来源:test_image.py
示例4: test_output_formats_png24
def test_output_formats_png24(self):
img = Image.new('RGBA', (100, 100))
image_opts = PNG_FORMAT.copy()
image_opts.colors = 0 # TODO image_opts
ir = ImageSource(img, image_opts=image_opts)
img = Image.open(ir.as_buffer())
eq_(img.mode, 'RGBA')
assert img.getpixel((0, 0)) == (0, 0, 0, 0)
开发者ID:tjay,项目名称:mapproxy,代码行数:8,代码来源:test_image.py
示例5: test_merge_rgb_with_transp
def test_merge_rgb_with_transp(self):
img1 = ImageSource(Image.new('RGB', (10, 10), (255, 0, 255)))
raw = Image.new('RGB', (10, 10), (0, 255, 255))
raw.info = {'transparency': (0, 255, 255)} # make full transparent
img2 = ImageSource(raw)
result = merge_images([img1, img2], ImageOptions(transparent=False))
img = result.as_image()
eq_(img.getpixel((0, 0)), (255, 0, 255))
开发者ID:tjay,项目名称:mapproxy,代码行数:9,代码来源:test_image.py
示例6: create_debug_img
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
开发者ID:Geodan,项目名称:mapproxy,代码行数:9,代码来源:image.py
示例7: merge
def merge(self, sources, image_opts, size=None, bbox=None, bbox_srs=None, coverage=None):
if not sources:
return BlankImageSource(size=size, image_opts=image_opts, cacheable=True)
if size is None:
size = sources[0].size
# load src bands
src_img_bands = []
for i, layer_img in enumerate(sources):
img = layer_img.as_image()
if i not in self.max_band:
# do not split img if not requested by any op
src_img_bands.append(None)
continue
if self.max_band[i] == 3 and img.mode != 'RGBA':
# convert to RGBA if band idx 3 is requestd (e.g. P or RGB src)
img = img.convert('RGBA')
elif img.mode == 'P':
img = img.convert('RGB')
src_img_bands.append(img.split())
tmp_mode = self.mode
if tmp_mode == 'RGBA':
result_bands = [None, None, None, None]
elif tmp_mode == 'RGB':
result_bands = [None, None, None]
elif tmp_mode == 'L':
result_bands = [None]
else:
raise ValueError("unsupported destination mode %s", image_opts.mode)
for op in self.ops:
chan = src_img_bands[op.src_img][op.src_band]
if op.factor != 1.0:
chan = ImageMath.eval("convert(int(float(a) * %f), 'L')" % op.factor, a=chan)
if result_bands[op.dst_band] is None:
result_bands[op.dst_band] = chan
else:
result_bands[op.dst_band] = ImageChops.add(
result_bands[op.dst_band],
chan,
)
else:
result_bands[op.dst_band] = chan
for i, b in enumerate(result_bands):
if b is None:
# band not set
b = Image.new("L", size, 255 if i == 3 else 0)
result_bands[i] = b
result = Image.merge(tmp_mode, result_bands)
return ImageSource(result, size=size, image_opts=image_opts)
开发者ID:charleiWang,项目名称:mapproxy,代码行数:57,代码来源:merge.py
示例8: test_opacity_merge_mixed_modes
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_img_colors_eq(img, [
(10*10, (127, 127, 255, 255)),
])
开发者ID:tjay,项目名称:mapproxy,代码行数:10,代码来源:test_image.py
示例9: test_merge_L
def test_merge_L(self):
img1 = ImageSource(Image.new('RGBA', (10, 10), (255, 0, 255, 255)))
img2 = ImageSource(Image.new('L', (10, 10), 100))
# img2 overlays img1
result = merge_images([img1, img2], ImageOptions(transparent=True))
img = result.as_image()
assert_img_colors_eq(img, [
(10*10, (100, 100, 100, 255)),
])
开发者ID:tjay,项目名称:mapproxy,代码行数:10,代码来源:test_image.py
示例10: test_save_with_unsupported_transparency
def test_save_with_unsupported_transparency(self):
# check if encoding of non-RGB image with tuple as transparency
# works. workaround for Pillow #2633
img = Image.new('P', (100, 100))
img.info['transparency'] = (0, 0, 0)
image_opts = PNG_FORMAT.copy()
ir = ImageSource(img, image_opts=image_opts)
img = Image.open(ir.as_buffer())
eq_(img.mode, 'P')
开发者ID:LKajan,项目名称:mapproxy,代码行数:10,代码来源:test_image.py
示例11: create_image
def create_image(size, color=None, mode=None):
if color is not None:
if isinstance(color, string_type):
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
开发者ID:Geodan,项目名称:mapproxy,代码行数:13,代码来源:image.py
示例12: test_concatenation
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())
开发者ID:LKajan,项目名称:mapproxy,代码行数:15,代码来源:test_concat_legends.py
示例13: test_mask_partial_image_transparent
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]))
assert_img_colors_eq(result.as_image().getcolors(),
[(7500, (255, 255, 255, 0)), (2500, (100, 0, 200, 255))])
开发者ID:Geodan,项目名称:mapproxy,代码行数:7,代码来源:test_image_mask.py
示例14: create_image
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.compat.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, string_type):
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)
开发者ID:Geodan,项目名称:mapproxy,代码行数:30,代码来源:opts.py
示例15: test_layers_with_opacity
def test_layers_with_opacity(self):
# overlay with opacity -> request should not be combined
common_params = (r'?SERVICE=WMS&FORMAT=image%2Fpng'
'&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326&styles='
'&VERSION=1.1.1&BBOX=9.0,50.0,10.0,51.0'
'&WIDTH=200')
img_bg = create_tmp_image((200, 200), color=(0, 0, 0))
img_fg = create_tmp_image((200, 200), color=(255, 0, 128))
expected_req = [
({'path': '/service_a' + common_params + '&layers=a_one'},
{'body': img_bg, 'headers': {'content-type': 'image/png'}}),
({'path': '/service_a' + common_params + '&layers=a_two'},
{'body': img_fg, 'headers': {'content-type': 'image/png'}}),
]
with mock_httpd(('localhost', 42423), expected_req):
self.common_map_req.params.layers = 'opacity_base,opacity_overlay'
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/png')
data = BytesIO(resp.body)
assert is_png(data)
img = Image.open(data)
eq_(img.getcolors()[0], ((200*200),(127, 0, 64)))
开发者ID:GeoDodo,项目名称:mapproxy,代码行数:25,代码来源:test_combined_sources.py
示例16: assert_image_mode
def assert_image_mode(img, mode):
pos = img.tell()
try:
img = Image.open(img)
eq_(img.mode, mode)
finally:
img.seek(pos)
开发者ID:Geodan,项目名称:mapproxy,代码行数:7,代码来源:image.py
示例17: test_mask_partial_image_bgcolor
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))])
开发者ID:GeoDodo,项目名称:mapproxy,代码行数:7,代码来源:test_image_mask.py
示例18: image_mask_from_geom
def image_mask_from_geom(size, bbox, polygons):
mask = Image.new('L', size, 255)
if len(polygons) == 0:
return mask
transf = make_lin_transf(bbox, (0, 0) + size)
# use negative ~.1 pixel buffer
buffer = -0.1 * min((bbox[2] - bbox[0]) / size[0], (bbox[3] - bbox[1]) / size[1])
draw = ImageDraw.Draw(mask)
def draw_polygon(p):
draw.polygon([transf(coord) for coord in p.exterior.coords], fill=0)
for ring in p.interiors:
draw.polygon([transf(coord) for coord in ring.coords], fill=255)
for p in polygons:
# little bit smaller polygon does not include touched pixels outside coverage
buffered = p.buffer(buffer, resolution=1, join_style=2)
if buffered.is_empty: # can be empty after negative buffer
continue
if buffered.type == 'MultiPolygon':
# negative buffer can turn polygon into multipolygon
for p in buffered:
draw_polygon(p)
else:
draw_polygon(buffered)
return mask
开发者ID:LKajan,项目名称:mapproxy,代码行数:32,代码来源:mask.py
示例19: test_one_point
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)
开发者ID:tjay,项目名称:mapproxy,代码行数:7,代码来源:test_image.py
示例20: test_solid_paletted_image
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))
开发者ID:tjay,项目名称:mapproxy,代码行数:7,代码来源:test_image.py
注:本文中的mapproxy.compat.image.Image类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论