示例#1
0
 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())
示例#2
0
 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())
示例#3
0
 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
示例#4
0
    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
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())
     assert img.mode == "RGBA"
     assert img.getpixel((0, 0)) == (0, 0, 0, 0)
示例#6
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
示例#7
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)
示例#8
0
 def test_output_formats_greyscale_png(self):
     img = Image.new('L', (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
0
    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())
        assert img.mode == "P"
示例#10
0
    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')
示例#11
0
    def test_geotiff_tags(
        self, tmpdir, srs, bbox, size,
        expected_pixel_res, expected_origin, projected,
        compression,
    ):
        img = ImageSource(create_debug_img(size), georef=GeoReference(bbox=bbox, srs=SRS(srs)))
        fname = os.path.join(str(tmpdir), 'geo.tiff')

        img_opts = ImageOptions(format='tiff', encoding_options={'tiff_compression': compression})
        img2 = ImageSource(img.as_buffer(img_opts)).as_image()

        assert_geotiff_tags(img2, expected_origin, expected_pixel_res, srs, projected)
示例#12
0
 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)
示例#13
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
示例#14
0
 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))
         check_format(ir.as_buffer(), format)
示例#15
0
 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
示例#16
0
 def encoded_size(encoding_options):
     ir = ImageSource(create_debug_img((100, 100)), PNG_FORMAT)
     buf = ir.as_buffer(ImageOptions(format="tiff", encoding_options=encoding_options))
     return len(buf.read())
示例#17
0
 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())
示例#18
0
 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)
示例#19
0
 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)
示例#20
0
 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())
示例#21
0
 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
示例#22
0
 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)