当前位置: 首页>>代码示例>>Python>>正文


Python Image.open方法代码示例

本文整理汇总了Python中mapproxy.platform.image.Image.open方法的典型用法代码示例。如果您正苦于以下问题:Python Image.open方法的具体用法?Python Image.open怎么用?Python Image.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mapproxy.platform.image.Image的用法示例。


在下文中一共展示了Image.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_layers_with_opacity

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
 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)))
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:27,代码来源:test_combined_sources.py

示例2: assert_image_mode

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
def assert_image_mode(img, mode):
    pos = img.tell()
    try:
        img = Image.open(img)
        eq_(img.mode, mode)
    finally:
        img.seek(pos)
开发者ID:cedricmoullet,项目名称:mapproxy,代码行数:9,代码来源:image.py

示例3: test_get_tile_uncached

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
 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))])
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:10,代码来源:test_seed_only.py

示例4: test_get_map

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
 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))])
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:10,代码来源:test_mapserver.py

示例5: test_output_formats_png24

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
 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:atrawog,项目名称:mapproxy,代码行数:10,代码来源:test_image.py

示例6: is_transparent

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
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)
开发者ID:ChrisRenton,项目名称:mapproxy,代码行数:11,代码来源:image.py

示例7: test_get_tile_cached

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
 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)
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:11,代码来源:test_seed_only.py

示例8: test_get_map_cached

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
 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)
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:11,代码来源:test_seed_only.py

示例9: test_get_map_uncached

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
 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))])
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:11,代码来源:test_seed_only.py

示例10: test_get_map_outside

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
 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))])
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:12,代码来源:test_coverage.py

示例11: test_get_map_outside_transparent

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
 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
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:13,代码来源:test_coverage.py

示例12: test_get_map_transparent

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
    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)))
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:13,代码来源:test_mapnik.py

示例13: test_get_tile_with_watermark_cache

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
 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))
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:13,代码来源:test_tms.py

示例14: bgcolor_ratio

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
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
开发者ID:cedricmoullet,项目名称:mapproxy,代码行数:13,代码来源:image.py

示例15: test_get_map_outside_coverage

# 需要导入模块: from mapproxy.platform.image import Image [as 别名]
# 或者: from mapproxy.platform.image.Image import open [as 别名]
    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)))
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:14,代码来源:test_mapnik.py


注:本文中的mapproxy.platform.image.Image.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。