test_webp.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:pywebp 作者: anibali 项目源码 文件源码
def test_image(self):
    img = Image.new('RGB', (32, 16))
    draw = ImageDraw.Draw(img)
    draw.rectangle([0, 0, 7, 15], fill=(255, 0, 0))

    pic = webp.WebPPicture.from_pil(img)
    config = webp.WebPConfig.new(lossless=True)
    buf = pic.encode(config).buffer()

    with TemporaryDirectory() as tmpdir:
      file_name = os.path.join(tmpdir, 'image.webp')
      with open(file_name, 'wb') as f:
        f.write(buf)

      with open(file_name, 'rb') as f:
        webp_data = webp.WebPData.from_buffer(f.read())
        arr = webp_data.decode(color_mode=webp.WebPColorMode.RGB)

        expected = np.asarray(img, dtype=np.uint8)
        np.testing.assert_array_equal(arr, expected)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号