def test_clipped_bgcolor(self, app): with tmp_image((256, 256), format="png", color=(255, 0, 0)) as img: expected_req = ( { "path": r"/service?LAYERs=bar&SERVICE=WMS&FORMAT=image%2Fpng" "&REQUEST=GetMap&HEIGHT=100&SRS=EPSG%3A25832&styles=" "&VERSION=1.1.1&BBOX=0.0,3500000.0,100.0,3500100.0" "&WIDTH=50" }, { "body": img.read(), "headers": { "content-type": "image/png" } }, ) with mock_httpd(("localhost", 42423), [expected_req]): resp = app.get( "http://localhost/service?SERVICE=WMS&REQUEST=GetMap" "&LAYERS=direct&STYLES=" "&WIDTH=100&HEIGHT=100&FORMAT=image/png" "&BBOX=-100,3500000,100,3500100&SRS=EPSG:25832" "&VERSION=1.1.0&TRANSPARENT=FALSE&BGCOLOR=0x00ff00") assert resp.content_type == "image/png" assert is_png(resp.body) assert_colors_equal( img_from_buf(resp.body).convert("RGBA"), [(50 * 100, [255, 0, 0, 255]), (50 * 100, [0, 255, 0, 255])], )
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_colors_equal(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))])
def test_clipped_bgcolor(self): with tmp_image((256, 256), format='png', color=(255, 0, 0)) as img: expected_req = ({ 'path': r'/service?LAYERs=bar&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetMap&HEIGHT=100&SRS=EPSG%3A25832&styles=' '&VERSION=1.1.1&BBOX=0.0,3500000.0,100.0,3500100.0' '&WIDTH=50' }, { 'body': img.read(), 'headers': { 'content-type': 'image/png' } }) with mock_httpd(('localhost', 42423), [expected_req]): resp = self.app.get( 'http://localhost/service?SERVICE=WMS&REQUEST=GetMap' '&LAYERS=direct&STYLES=' '&WIDTH=100&HEIGHT=100&FORMAT=image/png' '&BBOX=-100,3500000,100,3500100&SRS=EPSG:25832' '&VERSION=1.1.0&TRANSPARENT=FALSE&BGCOLOR=0x00ff00') eq_(resp.content_type, 'image/png') assert is_png(resp.body) assert_colors_equal( img_from_buf(resp.body).convert('RGBA'), [(50 * 100, [255, 0, 0, 255]), (50 * 100, [0, 255, 0, 255])])
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_colors_equal(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))])
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)), ])
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)), ])
def test_out_of_extent_bgcolor(self): resp = self.app.get('http://localhost/service?SERVICE=WMS&REQUEST=GetMap' '&LAYERS=direct&STYLES=' '&WIDTH=100&HEIGHT=100&FORMAT=image/png' '&BBOX=-10000,0,0,1000&SRS=EPSG:25832' '&VERSION=1.1.0&TRANSPARENT=FALSE&BGCOLOR=0xff0000') # red response eq_(resp.content_type, 'image/png') assert is_png(resp.body) assert_colors_equal(img_from_buf(resp.body).convert('RGBA'), [(100 * 100, [255, 0, 0, 255])])
def test_out_of_extent_bgcolor(self, app): resp = app.get("http://localhost/service?SERVICE=WMS&REQUEST=GetMap" "&LAYERS=direct&STYLES=" "&WIDTH=100&HEIGHT=100&FORMAT=image/png" "&BBOX=-10000,0,0,1000&SRS=EPSG:25832" "&VERSION=1.1.0&TRANSPARENT=FALSE&BGCOLOR=0xff0000") # red response assert resp.content_type == "image/png" assert is_png(resp.body) assert_colors_equal( img_from_buf(resp.body).convert("RGBA"), [(100 * 100, [255, 0, 0, 255])])
def test_wms_cached_response(self): expected_req = [({'path': '/foo/1/1/0.png'}, {'body': b'no content', 'status': 204, 'headers': {'content-type': 'text/plain'}}), ] with mock_httpd(('localhost', 42423), expected_req): resp = self.app.get(self.common_map_req) eq_(resp.content_type, 'image/png') assert 'Cache-Control' not in resp.headers img = img_from_buf(resp.body) assert_colors_equal(img, [(250 * 250, (100, 200, 50, 250))]) self.created_tiles.append('tilesource_cache_EPSG4326/01/000/000/001/000/000/000.png')
def test_out_of_extent_bgcolor(self): resp = self.app.get( 'http://localhost/service?SERVICE=WMS&REQUEST=GetMap' '&LAYERS=direct&STYLES=' '&WIDTH=100&HEIGHT=100&FORMAT=image/png' '&BBOX=-10000,0,0,1000&SRS=EPSG:25832' '&VERSION=1.1.0&TRANSPARENT=FALSE&BGCOLOR=0xff0000') # red response eq_(resp.content_type, 'image/png') assert is_png(resp.body) assert_colors_equal( img_from_buf(resp.body).convert('RGBA'), [(100 * 100, [255, 0, 0, 255])])
def test_composite_merge_opacity(self): if not hasattr(Image, 'alpha_composite'): raise SkipTest() bg = Image.new('RGBA', size=(100, 100), color=(255, 0, 255, 255)) bg = ImageSource(bg) fg = Image.new('RGBA', size=(100, 100), color=(0, 0, 0, 0)) draw = ImageDraw.Draw(fg) draw.rectangle((10, 10, 89, 89), fill=(0, 255, 255, 255)) fg = ImageSource(fg, image_opts=ImageOptions(opacity=0.5)) result = merge_images([bg, fg], ImageOptions(transparent=True)) img = result.as_image() eq_(img.mode, 'RGBA') assert_colors_equal(img, [(3600, (255, 0, 255, 255)), (6400, (128, 127, 255, 255))])
def test_composite_merge_opacity(self): if not hasattr(Image, 'alpha_composite'): raise SkipTest() bg = Image.new('RGBA', size=(100, 100), color=(255, 0, 255, 255)) bg = ImageSource(bg) fg = Image.new('RGBA', size =(100, 100), color=(0, 0, 0, 0)) draw = ImageDraw.Draw(fg) draw.rectangle((10, 10, 89, 89), fill=(0, 255, 255, 255)) fg = ImageSource(fg, image_opts=ImageOptions(opacity=0.5)) result = merge_images([bg, fg], ImageOptions(transparent=True)) img = result.as_image() eq_(img.mode, 'RGBA') assert_colors_equal(img, [ (3600, (255, 0, 255, 255)), (6400, (128, 127, 255, 255))])
def test_clipped_bgcolor(self): with tmp_image((256, 256), format='png', color=(255, 0, 0)) as img: expected_req = ({'path': r'/service?LAYERs=bar&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetMap&HEIGHT=100&SRS=EPSG%3A25832&styles=' '&VERSION=1.1.1&BBOX=0.0,3500000.0,100.0,3500100.0' '&WIDTH=50'}, {'body': img.read(), 'headers': {'content-type': 'image/png'}}) with mock_httpd(('localhost', 42423), [expected_req]): resp = self.app.get('http://localhost/service?SERVICE=WMS&REQUEST=GetMap' '&LAYERS=direct&STYLES=' '&WIDTH=100&HEIGHT=100&FORMAT=image/png' '&BBOX=-100,3500000,100,3500100&SRS=EPSG:25832' '&VERSION=1.1.0&TRANSPARENT=FALSE&BGCOLOR=0x00ff00') eq_(resp.content_type, 'image/png') assert is_png(resp.body) assert_colors_equal(img_from_buf(resp.body).convert('RGBA'), [(50 * 100, [255, 0, 0, 255]), (50 * 100, [0, 255, 0, 255])])
def test_wms_cached_response(self): expected_req = [ ({ 'path': '/foo/1/1/0.png' }, { 'body': b'no content', 'status': 204, 'headers': { 'content-type': 'text/plain' } }), ] with mock_httpd(('localhost', 42423), expected_req): resp = self.app.get(self.common_map_req) eq_(resp.content_type, 'image/png') assert 'Cache-Control' not in resp.headers img = img_from_buf(resp.body) assert_colors_equal(img, [(250 * 250, (100, 200, 50, 250))]) self.created_tiles.append( 'tilesource_cache_EPSG4326/01/000/000/001/000/000/000.png')
def test_wms_cached_response(self, app, cache_dir): expected_req = [( { "path": "/foo/1/1/0.png" }, { "body": b"no content", "status": 204, "headers": { "content-type": "text/plain" }, }, )] with mock_httpd(("localhost", 42423), expected_req): resp = app.get(self.common_map_req) assert resp.content_type == "image/png" assert "Cache-Control" not in resp.headers img = img_from_buf(resp.body) assert_colors_equal(img, [(250 * 250, (100, 200, 50, 250))]) assert cache_dir.join( "tilesource_cache_EPSG4326/01/000/000/001/000/000/000.png" ).check()