예제 #1
0
    def test_combined_transp_color(self):
        # merged to one request because both layers share the same transparent_color
        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&transparent=True')

        with tmp_image((200, 200), color=(255, 0, 0), format='png') as img:
            img = img.read()
            expected_req = [
                ({
                    'path':
                    '/service_a' + common_params +
                    '&layers=a_iopts_one,a_iopts_two'
                }, {
                    'body': img,
                    'headers': {
                        'content-type': 'image/png'
                    }
                }),
            ]

            with mock_httpd(('localhost', 42423), expected_req):
                self.common_map_req.params.layers = 'layer_image_opts1,layer_image_opts2'
                self.common_map_req.params.transparent = True
                resp = self.app.get(self.common_map_req)
                resp.content_type = 'image/png'
                data = StringIO(resp.body)
                assert is_png(data)
                img = Image.open(data)
                eq_(img.getcolors()[0], ((200 * 200), (255, 0, 0, 0)))
 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 = StringIO(resp.body)
         assert is_png(data)
         img = Image.open(data)
         eq_(img.getcolors()[0], ((200*200),(127, 0, 64)))
예제 #3
0
def assert_image_mode(img, mode):
    pos = img.tell()
    try:
        img = Image.open(img)
        eq_(img.mode, mode)
    finally:
        img.seek(pos)
예제 #4
0
 def test_get_legendgraphic_111(self):
     self.common_lg_req_111.params['scale'] = '5.0'
     with tmp_image((256, 256), format='png') as img:
         img_data = img.read()
         expected_req1 = ({
             'path':
             r'/service?LAYER=foo&SERVICE=WMS&FORMAT=image%2Fpng'
             '&REQUEST=GetLegendGraphic&SCALE=5.0&'
             '&VERSION=1.1.1&SLD_VERSION=1.1.0'
         }, {
             'body': img_data,
             'headers': {
                 'content-type': 'image/png'
             }
         })
         expected_req2 = ({
             'path':
             r'/service?LAYER=bar&SERVICE=WMS&FORMAT=image%2Fpng'
             '&REQUEST=GetLegendGraphic&SCALE=5.0&'
             '&VERSION=1.1.1&SLD_VERSION=1.1.0'
         }, {
             'body': img_data,
             'headers': {
                 'content-type': 'image/png'
             }
         })
         with mock_httpd(('localhost', 42423),
                         [expected_req1, expected_req2]):
             resp = self.app.get(self.common_lg_req_111)
             eq_(resp.content_type, 'image/png')
             data = StringIO(resp.body)
             assert is_png(data)
             assert Image.open(data).size == (256, 512)
예제 #5
0
def assert_image_mode(img, mode):
    pos = img.tell()
    try:
        img = Image.open(img)
        eq_(img.mode, mode)
    finally:
        img.seek(pos)
예제 #6
0
 def test_transparent_watermark_tile(self):
     with tmp_image((256, 256),
                    format='png',
                    color=(0, 0, 0, 0),
                    mode='RGBA') as img:
         expected_req = ({
             'path':
             r'/service?LAYERs=blank&SERVICE=WMS&FORMAT=image%2Fpng'
             '&REQUEST=GetMap&HEIGHT=256&SRS=EPSG%3A4326&styles='
             '&VERSION=1.1.1&BBOX=-180.0,-90.0,0.0,90.0'
             '&WIDTH=256'
         }, {
             'body': img.read(),
             'headers': {
                 'content-type': 'image/jpeg'
             }
         })
         with mock_httpd(('localhost', 42423), [expected_req]):
             resp = self.app.get(
                 '/tms/1.0.0/watermark_transp/EPSG4326/0/0/0.png')
             eq_(resp.content_type, 'image/png')
             img = Image.open(StringIO(resp.body))
             colors = img.getcolors()
             assert len(colors) >= 2
             eq_(sorted(colors)[-1][1], (0, 0, 0, 0))
예제 #7
0
 def test_get_map(self):
     resp = self.app.get(self.common_map_req)
     eq_(resp.content_type, 'image/png')
     data = StringIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     img = img.convert('RGB')
     eq_(img.getcolors(), [(200*200, (255, 0, 0))])
예제 #8
0
 def test_get_tile_uncached(self):
     resp = self.app.get('/tms/1.0.0/wms_cache/0/0/0.jpeg')
     eq_(resp.content_type, 'image/png')
     data = StringIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGBA')
     eq_(img.getcolors(), [(256*256, (255, 255, 255, 0))])
예제 #9
0
 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)
예제 #10
0
 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)
예제 #11
0
 def test_output_formats_png8(self):
     img = Image.new('RGBA', (100, 100))
     ir = ImageSource(img, image_opts=PNG_FORMAT)
     img = Image.open(
         ir.as_buffer(
             ImageOptions(colors=256, transparent=True,
                          format='image/png')))
     assert img.mode == 'P'
     assert img.getpixel((0, 0)) == 255
예제 #12
0
 def test_get_map_cached(self):
     resp = self.app.get(self.common_map_req)
     eq_(resp.content_type, 'image/png')
     data = StringIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGB')
     # cached image has more that 256 colors, getcolors -> None
     eq_(img.getcolors(), None)
예제 #13
0
 def test_get_map_uncached(self):
     self.common_map_req.params['bbox'] = '10,10,20,20'
     resp = self.app.get(self.common_map_req)
     eq_(resp.content_type, 'image/png')
     data = StringIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGBA')
     eq_(img.getcolors(), [(200*200, (255, 255, 255, 0))])
예제 #14
0
 def test_get_tile_cached(self):
     resp = self.app.get('/tms/1.0.0/wms_cache/0/0/1.jpeg')
     eq_(resp.content_type, 'image/jpeg')
     data = StringIO(resp.body)
     assert is_jpeg(data)
     img = Image.open(data)
     eq_(img.mode, 'RGB')
     # cached image has more that 256 colors, getcolors -> None
     eq_(img.getcolors(), None)
예제 #15
0
def is_transparent(img_data):
    data = StringIO(img_data)
    img = Image.open(data)
    if img.mode == "P":
        img = img.convert("RGBA")
    if img.mode == "RGBA":
        return any(img.histogram()[-256:-1])

    raise NotImplementedError("assert_is_transparent works only for RGBA images, got %s image" % img.mode)
예제 #16
0
 def test_get_map_outside(self):
     self.common_map_req.params.bbox = -90, 0, 0, 90
     self.common_map_req.params['bgcolor'] = '0xff0005'
     resp = self.app.get(self.common_map_req)
     eq_(resp.content_type, 'image/png')
     data = StringIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGB')
     eq_(img.getcolors(), [(200 * 200, (255, 0, 5))])
예제 #17
0
파일: image.py 프로젝트: imclab/mapproxy
def is_transparent(img_data):
    data = StringIO(img_data)
    img = Image.open(data)
    if img.mode == 'P':
        img = img.convert('RGBA')
    if img.mode == 'RGBA':
        return any(img.histogram()[-256:-1])

    raise NotImplementedError(
        'assert_is_transparent works only for RGBA images, got %s image' % img.mode)
예제 #18
0
 def test_get_map_outside(self):
     self.common_map_req.params.bbox = -90, 0, 0, 90
     self.common_map_req.params['bgcolor'] = '0xff0005'
     resp = self.app.get(self.common_map_req)
     eq_(resp.content_type, 'image/png')
     data = StringIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGB')
     eq_(img.getcolors(), [(200*200, (255, 0, 5))])
예제 #19
0
    def test_get_map_transparent(self):
        req = (r'/service?LAYERs=mapnik_transparent&SERVICE=WMS&FORMAT=image%2Fpng'
                '&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326'
                '&VERSION=1.1.1&BBOX=-90,-90,0,0&styles='
                '&WIDTH=200&transparent=True')

        resp = self.app.get(req)
        data = StringIO(resp.body)
        img = Image.open(data)
        colors = img.getcolors(1)
        eq_(colors[0], (40000, (0, 0, 0, 0)))
예제 #20
0
def bgcolor_ratio(img_data):
    """
    Return the ratio of the primary/bg color. 1 == only bg color.
    """
    data = StringIO(img_data)
    img = Image.open(data)
    total_colors = img.size[0] * img.size[1]
    colors = img.getcolors()
    colors.sort()
    bgcolor = colors[-1][0]
    return bgcolor / total_colors
예제 #21
0
def bgcolor_ratio(img_data):
    """
    Return the ratio of the primary/bg color. 1 == only bg color.
    """
    data = StringIO(img_data)
    img = Image.open(data)
    total_colors = img.size[0] * img.size[1]
    colors = img.getcolors()
    colors.sort()
    bgcolor = colors[-1][0]
    return bgcolor/total_colors
예제 #22
0
 def test_get_map_outside_transparent(self):
     self.common_map_req.params.bbox = -90, 0, 0, 90
     self.common_map_req.params.transparent = True
     resp = self.app.get(self.common_map_req)
     eq_(resp.content_type, 'image/png')
     data = StringIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGBA')
     eq_(img.getcolors()[0][0], 200 * 200)
     eq_(img.getcolors()[0][1][3], 0)  # transparent
예제 #23
0
파일: test_tms.py 프로젝트: imclab/mapproxy
 def test_get_tile_with_watermark_cache(self):
     with tmp_image((256, 256), format='png', color=(0, 0, 0)) as img:
         expected_req = ({'path': r'/tiles/01/000/000/000/000/000/000.png'},
                          {'body': img.read(), 'headers': {'content-type': 'image/png'}})
         with mock_httpd(('localhost', 42423), [expected_req]):
             resp = self.app.get('/tms/1.0.0/watermark_cache/0/0/0.png')
             eq_(resp.content_type, 'image/png')
             img = Image.open(StringIO(resp.body))
             colors = img.getcolors()
             assert len(colors) >= 2
             eq_(sorted(colors)[-1][1], (0, 0, 0))
예제 #24
0
 def test_get_map_outside_transparent(self):
     self.common_map_req.params.bbox = -90, 0, 0, 90
     self.common_map_req.params.transparent = True
     resp = self.app.get(self.common_map_req)
     eq_(resp.content_type, 'image/png')
     data = StringIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGBA')
     eq_(img.getcolors()[0][0], 200*200)
     eq_(img.getcolors()[0][1][3], 0) # transparent
예제 #25
0
 def test_02_get_legendgraphic_layer_static_url(self):
     self.common_lg_req_111.params['layer'] = 'wms_layer_static_url'
     with tmp_image((256, 256), format='png') as img:
         img_data = img.read()
         expected_req1 = ({'path': r'/staticlegend_layer.png'},
                          {'body': img_data, 'headers': {'content-type': 'image/png'}})
         with mock_httpd(('localhost', 42423), [expected_req1]):
             resp = self.app.get(self.common_lg_req_111)
             eq_(resp.content_type, 'image/png')
             data = StringIO(resp.body)
             assert is_png(data)
             assert Image.open(data).size == (256,256)
예제 #26
0
    def test_get_map_outside_coverage(self):
        req = (r'/service?LAYERs=mapnik&SERVICE=WMS&FORMAT=image%2Fpng'
               '&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326'
               '&VERSION=1.1.1&BBOX=-175,-85,-172,-82&styles='
               '&WIDTH=200&&BGCOLOR=0x00ff00')

        resp = self.app.get(req)
        data = StringIO(resp.body)
        img = Image.open(data)
        colors = img.getcolors(1)
        # wms request bg color
        eq_(colors[0], (40000, (0, 255, 0)))
예제 #27
0
def is_transparent(img_data):
    data = StringIO(img_data)
    img = Image.open(data)
    if img.mode == 'RGBA':
        return any(img.histogram()[-256:-1])        
    elif img.mode == 'P':
        colors = img.getcolors()
        if len(colors) != 1:
            return False
    
    raise NotImplementedError(
        'assert_is_transparent works only for RGBA images, got %s image' % img.mode)
예제 #28
0
    def test_get_map_outside_coverage(self):
        req = (r'/service?LAYERs=mapnik&SERVICE=WMS&FORMAT=image%2Fpng'
                '&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326'
                '&VERSION=1.1.1&BBOX=-175,-85,-172,-82&styles='
                '&WIDTH=200&&BGCOLOR=0x00ff00')

        resp = self.app.get(req)
        data = StringIO(resp.body)
        img = Image.open(data)
        colors = img.getcolors(1)
        # wms request bg color
        eq_(colors[0], (40000, (0, 255, 0)))
예제 #29
0
    def test_get_map(self):
        req = (r'/service?LAYERs=mapnik&SERVICE=WMS&FORMAT=image%2Fpng'
               '&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326'
               '&VERSION=1.1.1&BBOX=-90,-90,0,0&styles='
               '&WIDTH=200&')

        resp = self.app.get(req)
        data = StringIO(resp.body)
        img = Image.open(data)
        colors = img.getcolors(1)
        # map bg color
        eq_(colors[0], (40000, (255, 0, 0, 255)))
예제 #30
0
def is_transparent(img_data):
    data = StringIO(img_data)
    img = Image.open(data)
    if img.mode == 'RGBA':
        return any(img.histogram()[-256:-1])
    elif img.mode == 'P':
        colors = img.getcolors()
        if len(colors) != 1:
            return False

    raise NotImplementedError(
        'assert_is_transparent works only for RGBA images, got %s image' %
        img.mode)
예제 #31
0
    def test_exception(self):
        self.req["exceptions"] = "blank"
        req = WMSMapRequest(self.req)
        req_ex = RequestError("the exception message", request=req)

        response = req_ex.render()
        assert response.content_type == "image/png"
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
        eq_(img.getpixel((0, 0)), 0)  # pallete image
        eq_(img.getpalette()[0:3], [255, 255, 255])
예제 #32
0
    def test_exception(self):
        self.req.set("exceptions", "inimage")
        self.req.set("transparent", "true")

        req = WMSMapRequest(self.req)
        req_ex = RequestError("the exception message", request=req)

        response = req_ex.render()
        assert response.content_type == "image/png"
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
예제 #33
0
    def test_exception(self):
        self.req['exceptions'] = 'blank'
        req = WMSMapRequest(self.req)
        req_ex = RequestError('the exception message', request=req)

        response = req_ex.render()
        assert response.content_type == 'image/png'
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
        eq_(img.getpixel((0, 0)), 0)  #pallete image
        eq_(img.getpalette()[0:3], [255, 255, 255])
예제 #34
0
    def test_exception(self):
        self.req.set('exceptions', 'inimage')
        self.req.set('transparent', 'true')

        req = WMSMapRequest(self.req)
        req_ex = RequestError('the exception message', request=req)

        response = req_ex.render()
        assert response.content_type == 'image/png'
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
예제 #35
0
    def test_get_map(self):
        req = (
            r"/service?LAYERs=mapnik&SERVICE=WMS&FORMAT=image%2Fpng"
            "&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326"
            "&VERSION=1.1.1&BBOX=-90,-90,0,0&styles="
            "&WIDTH=200&"
        )

        resp = self.app.get(req)
        data = StringIO(resp.body)
        img = Image.open(data)
        colors = img.getcolors(1)
        # map bg color
        eq_(colors[0], (40000, (255, 0, 0, 255)))
예제 #36
0
 def test_transparent_watermark_tile(self):
     with tmp_image((256, 256), format='png', color=(0, 0, 0, 0), mode='RGBA') as img:
         expected_req = ({'path': r'/service?LAYERs=blank&SERVICE=WMS&FORMAT=image%2Fpng'
                                    '&REQUEST=GetMap&HEIGHT=256&SRS=EPSG%3A4326&styles='
                                    '&VERSION=1.1.1&BBOX=-180.0,-90.0,0.0,90.0'
                                    '&WIDTH=256'},
                          {'body': img.read(), 'headers': {'content-type': 'image/jgeg'}})
         with mock_httpd(('localhost', 42423), [expected_req]):
             resp = self.app.get('/tms/1.0.0/watermark_transp/EPSG4326/0/0/0.png')
             eq_(resp.content_type, 'image/png')
             img = Image.open(StringIO(resp.body))
             colors = img.getcolors()
             assert len(colors) >= 2
             eq_(sorted(colors)[-1][1], (0, 0, 0, 0))
예제 #37
0
    def test_exception_w_transparent(self):
        self.req.set('exceptions', 'inimage')
        self.req.set('transparent', 'true')

        req = WMSMapRequest(self.req)
        req_ex = RequestError('the exception message', request=req)

        response = req_ex.render()
        assert response.content_type == 'image/png'
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
        eq_(sorted([x for x in img.histogram() if x > 25]), [377, 14623])
        img = img.convert('RGBA')
        eq_(img.getpixel((0, 0))[3], 0)
예제 #38
0
 def test_get_map_intersection(self):
     self.created_tiles.append('wms_cache_EPSG4326/03/000/000/004/000/000/002.jpeg')
     with tmp_image((256, 256), format='jpeg') as img:
         expected_req = ({'path': r'/service?LAYERs=foo,bar&SERVICE=WMS&FORMAT=image%2Fjpeg'
                                   '&REQUEST=GetMap&HEIGHT=91&SRS=EPSG%3A4326&styles='
                                   '&VERSION=1.1.1&BBOX=10,15,30,31'
                                   '&WIDTH=114'},
                         {'body': img.read(), 'headers': {'content-type': 'image/jpeg'}})
         with mock_httpd(('localhost', 42423), [expected_req]):
             self.common_map_req.params.bbox = 0, 0, 40, 40
             self.common_map_req.params.transparent = True
             resp = self.app.get(self.common_map_req)
             eq_(resp.content_type, 'image/png')
             data = StringIO(resp.body)
             assert is_png(data)
             eq_(Image.open(data).mode, 'RGBA')
예제 #39
0
    def test_exception_w_transparent(self):
        self.req.set("exceptions", "inimage")
        self.req.set("transparent", "true")

        req = WMSMapRequest(self.req)
        req_ex = RequestError("the exception message", request=req)

        response = req_ex.render()
        assert response.content_type == "image/png"
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
        eq_(sorted([x for x in img.histogram() if x > 25]), [377, 14623])
        img = img.convert("RGBA")
        eq_(img.getpixel((0, 0))[3], 0)
예제 #40
0
    def test_exception_w_transparent(self):
        self.req.set("exceptions", "blank")
        self.req.set("transparent", "true")

        req = WMSMapRequest(self.req)
        req_ex = RequestError("the exception message", request=req)

        response = req_ex.render()
        assert response.content_type == "image/png"
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
        assert img.mode == "P"
        img = img.convert("RGBA")
        eq_(img.getpixel((0, 0))[3], 0)
예제 #41
0
    def test_exception_w_transparent(self):
        self.req.set('exceptions', 'blank')
        self.req.set('transparent', 'true')

        req = WMSMapRequest(self.req)
        req_ex = RequestError('the exception message', request=req)

        response = req_ex.render()
        assert response.content_type == 'image/png'
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
        assert img.mode == 'P'
        img = img.convert('RGBA')
        eq_(img.getpixel((0, 0))[3], 0)
예제 #42
0
 def test_wms_transparent(self):
     req = WMS111MapRequest(
         url='/service?',
         param=dict(
             service='WMS', version='1.1.1', bbox='-180,0,0,80',
             width='200', height='200', layers='wms_cache_transparent',
             srs='EPSG:4326', format='image/png',
             styles='', request='GetMap', transparent='True'
         )
     )
     resp = self.app.get(
         req, extra_environ={'mapproxy.decorate_img': to_greyscale}
     )
     data = StringIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGBA')
예제 #43
0
 def test_wms(self):
     req = WMS111MapRequest(url='/service?',
                            param=dict(service='WMS',
                                       version='1.1.1',
                                       bbox='-180,0,0,80',
                                       width='200',
                                       height='200',
                                       layers='wms_cache',
                                       srs='EPSG:4326',
                                       format='image/png',
                                       styles='',
                                       request='GetMap'))
     resp = self.app.get(
         req, extra_environ={'mapproxy.decorate_img': to_greyscale})
     data = StringIO(resp.body)
     assert is_png(data)
     img = Image.open(data)
     eq_(img.mode, 'RGB')
예제 #44
0
 def test_get_legendgraphic_111(self):
     self.common_lg_req_111.params['scale'] = '5.0'
     with tmp_image((256, 256), format='png') as img:
         img_data = img.read()
         expected_req1 = ({'path': r'/service?LAYER=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                                   '&REQUEST=GetLegendGraphic&SCALE=5.0&'
                                   '&VERSION=1.1.1&SLD_VERSION=1.1.0'},
                          {'body': img_data, 'headers': {'content-type': 'image/png'}})
         expected_req2 = ({'path': r'/service?LAYER=bar&SERVICE=WMS&FORMAT=image%2Fpng'
                                   '&REQUEST=GetLegendGraphic&SCALE=5.0&'
                                   '&VERSION=1.1.1&SLD_VERSION=1.1.0'},
                          {'body': img_data, 'headers': {'content-type': 'image/png'}})
         with mock_httpd(('localhost', 42423), [expected_req1, expected_req2]):
             resp = self.app.get(self.common_lg_req_111)
             eq_(resp.content_type, 'image/png')
             data = StringIO(resp.body)
             assert is_png(data)
             assert Image.open(data).size == (256,512)
예제 #45
0
 def test_02_get_legendgraphic_layer_static_url(self):
     self.common_lg_req_111.params['layer'] = 'wms_layer_static_url'
     with tmp_image((256, 256), format='png') as img:
         img_data = img.read()
         expected_req1 = ({
             'path': r'/staticlegend_layer.png'
         }, {
             'body': img_data,
             'headers': {
                 'content-type': 'image/png'
             }
         })
         with mock_httpd(('localhost', 42423), [expected_req1]):
             resp = self.app.get(self.common_lg_req_111)
             eq_(resp.content_type, 'image/png')
             data = StringIO(resp.body)
             assert is_png(data)
             assert Image.open(data).size == (256, 256)
예제 #46
0
파일: image.py 프로젝트: atrawog/mapproxy
def is_transparent(img_data):
    data = StringIO(img_data)
    img = Image.open(data)
    if img.mode == 'RGBA':
        colors = img.getcolors()
        if len(colors) != 1:
            return False
        count, color = colors[0]
        if color[3] != 0:
            return False
        return True
    elif img.mode == 'P':
        colors = img.getcolors()
        if len(colors) != 1:
            return False
    
    raise NotImplementedError(
        'assert_is_transparent works only for RGBA images, got %s image' % img.mode)
예제 #47
0
    def as_image(self):
        """
        Returns the image or the loaded image.
        
        :rtype: PIL `Image`
        """
        if not self._img:
            self._make_seekable_buf()
            log.debug('file(%s) -> image', self._fname or self._buf)

            try:
                img = Image.open(self._buf)
            except StandardError:
                self.close_buffers()
                raise
            self._img = img
        if self.image_opts and self.image_opts.transparent and self._img.mode == 'P':
            self._img = self._img.convert('RGBA')
        return self._img
예제 #48
0
    def as_image(self):
        """
        Returns the image or the loaded image.

        :rtype: PIL `Image`
        """
        if not self._img:
            self._make_seekable_buf()
            log.debug('file(%s) -> image', self._fname or self._buf)

            try:
                img = Image.open(self._buf)
            except StandardError:
                self.close_buffers()
                raise
            self._img = img
        if self.image_opts and self.image_opts.transparent and self._img.mode == 'P':
            self._img = self._img.convert('RGBA')
        return self._img
예제 #49
0
 def test_combined_transp_color(self):
     # merged to one request because both layers share the same transparent_color
     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&transparent=True')
     
     with tmp_image((200, 200), color=(255, 0, 0), format='png') as img:
         img = img.read()
         expected_req = [({'path': '/service_a' + common_params + '&layers=a_iopts_one,a_iopts_two'},
                          {'body': img, 'headers': {'content-type': 'image/png'}}),
                         ]
                         
         with mock_httpd(('localhost', 42423), expected_req):
             self.common_map_req.params.layers = 'layer_image_opts1,layer_image_opts2'
             self.common_map_req.params.transparent = True
             resp = self.app.get(self.common_map_req)
             resp.content_type = 'image/png'
             data = StringIO(resp.body)
             assert is_png(data)
             img = Image.open(data)
             eq_(img.getcolors()[0], ((200*200),(255, 0, 0, 0)))
예제 #50
0
    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 = StringIO(resp.body)
            assert is_png(data)
            img = Image.open(data)
            eq_(img.getcolors()[0], ((200 * 200), (127, 0, 64)))
예제 #51
0
 def test_get_map_intersection(self):
     self.created_tiles.append(
         'wms_cache_EPSG4326/03/000/000/004/000/000/002.jpeg')
     with tmp_image((256, 256), format='jpeg') as img:
         expected_req = ({
             'path':
             r'/service?LAYERs=foo,bar&SERVICE=WMS&FORMAT=image%2Fjpeg'
             '&REQUEST=GetMap&HEIGHT=91&SRS=EPSG%3A4326&styles='
             '&VERSION=1.1.1&BBOX=10,15,30,31'
             '&WIDTH=113'
         }, {
             'body': img.read(),
             'headers': {
                 'content-type': 'image/jpeg'
             }
         })
         with mock_httpd(('localhost', 42423), [expected_req]):
             self.common_map_req.params.bbox = 0, 0, 40, 40
             self.common_map_req.params.transparent = True
             resp = self.app.get(self.common_map_req)
             eq_(resp.content_type, 'image/png')
             data = StringIO(resp.body)
             assert is_png(data)
             eq_(Image.open(data).mode, 'RGBA')
예제 #52
0
 def test_output_formats_png8(self):
     img = Image.new('RGBA', (100, 100))
     ir = ImageSource(img, image_opts=PNG_FORMAT)
     img = Image.open(ir.as_buffer(ImageOptions(colors=256, transparent=True, format='image/png')))
     assert img.mode == 'P'
     assert img.getpixel((0, 0)) == 255
예제 #53
0
def img_from_buf(buf):
    data = StringIO(buf)
    return Image.open(data)