本文整理汇总了Python中mapproxy.image.ImageSource类的典型用法代码示例。如果您正苦于以下问题:Python ImageSource类的具体用法?Python ImageSource怎么用?Python ImageSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ImageSource类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_transformed
def _get_transformed(self, query, format):
dst_srs = query.srs
src_srs = self._best_supported_srs(dst_srs)
dst_bbox = query.bbox
src_bbox = dst_srs.transform_bbox_to(src_srs, dst_bbox)
src_width, src_height = src_bbox[2]-src_bbox[0], src_bbox[3]-src_bbox[1]
ratio = src_width/src_height
dst_size = query.size
xres, yres = src_width/dst_size[0], src_height/dst_size[1]
if xres < yres:
src_size = dst_size[0], int(dst_size[0]/ratio + 0.5)
else:
src_size = int(dst_size[1]*ratio +0.5), dst_size[1]
src_query = MapQuery(src_bbox, src_size, src_srs, format)
if self.coverage and not self.coverage.contains(src_bbox, src_srs):
img = self._get_sub_query(src_query, format)
else:
resp = self.client.retrieve(src_query, format)
img = ImageSource(resp, size=src_size, image_opts=self.image_opts)
img = ImageTransformer(src_srs, dst_srs).transform(img, src_bbox,
query.size, dst_bbox, self.image_opts)
img.format = format
return img
示例2: 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)
示例3: 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')
示例4: test_from_non_seekable_file
def test_from_non_seekable_file(self):
with open(self.tmp_filename, 'rb') as tmp_file:
data = tmp_file.read()
class FileLikeDummy(object):
# "file" without seek, like urlopen response
def read(self):
return data
ir = ImageSource(FileLikeDummy(), 'png')
assert ir.as_buffer(seekable=True).read() == data
assert ir.as_image().size == (100, 100)
assert ir.as_buffer().read() == data
示例5: setup
def setup(self):
self.src_img = ImageSource(create_debug_img((200, 200), transparent=False))
self.src_srs = SRS(31467)
self.dst_size = (100, 150)
self.dst_srs = SRS(4326)
self.dst_bbox = (0.2, 45.1, 8.3, 53.2)
self.src_bbox = self.dst_srs.transform_bbox_to(self.src_srs, self.dst_bbox)
示例6: TestTransform
class TestTransform(object):
def setup(self):
self.src_img = ImageSource(create_debug_img((200, 200), transparent=False))
self.src_srs = SRS(31467)
self.dst_size = (100, 150)
self.dst_srs = SRS(4326)
self.dst_bbox = (0.2, 45.1, 8.3, 53.2)
self.src_bbox = self.dst_srs.transform_bbox_to(self.src_srs, self.dst_bbox)
def test_transform(self, mesh_div=4):
transformer = ImageTransformer(self.src_srs, self.dst_srs, mesh_div=mesh_div)
result = transformer.transform(self.src_img, self.src_bbox, self.dst_size, self.dst_bbox,
image_opts=ImageOptions(resampling='nearest'))
assert isinstance(result, ImageSource)
assert result.as_image() != self.src_img.as_image()
assert result.size == (100, 150)
def _test_compare_mesh_div(self):
"""
Create transformations with different div values.
"""
for div in [1, 2, 4, 6, 8, 12, 16]:
transformer = ImageTransformer(self.src_srs, self.dst_srs, mesh_div=div)
result = transformer.transform(self.src_img, self.src_bbox,
self.dst_size, self.dst_bbox)
result.as_image().save('/tmp/transform-%d.png' % (div,))
示例7: test_converted_output
def test_converted_output(self):
ir = ImageSource(self.tmp_filename, (100, 100), PNG_FORMAT)
assert is_png(ir.as_buffer())
assert is_jpeg(ir.as_buffer(JPEG_FORMAT))
assert is_jpeg(ir.as_buffer())
assert is_tiff(ir.as_buffer(TIFF_FORMAT))
assert is_tiff(ir.as_buffer())
示例8: test_output_formats_png8
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
示例9: test_output_formats
def test_output_formats(self):
img = Image.new('RGB', (100, 100))
for format in ['png', 'gif', 'tiff', 'jpeg', 'GeoTIFF', 'bmp']:
ir = ImageSource(img, (100, 100), image_opts=ImageOptions(format=format))
yield check_format, ir.as_buffer(), format
示例10: test_from_image
def test_from_image(self):
img = Image.new('RGBA', (100, 100))
ir = ImageSource(img, (100, 100), PNG_FORMAT)
assert ir.as_image() == img
assert is_png(ir.as_buffer())
示例11: test_from_file
def test_from_file(self):
with open(self.tmp_filename, 'rb') as tmp_file:
ir = ImageSource(tmp_file, 'png')
assert ir.as_buffer() == tmp_file
assert ir.as_image().size == (100, 100)
示例12: test_from_filename
def test_from_filename(self):
ir = ImageSource(self.tmp_filename, PNG_FORMAT)
assert is_png(ir.as_buffer())
assert ir.as_image().size == (100, 100)