Merge pull request #146 from wiredfool/webp_tests

Webp tests
This commit is contained in:
Alex Clark ☺ 2013-03-19 14:52:07 -07:00
commit 79ca29f2f5
4 changed files with 44 additions and 1 deletions

View File

@ -23,7 +23,7 @@ def _save(im, fp, filename):
raise IOError("cannot write mode %s as WEBP" % im.mode)
quality = im.encoderinfo.get("quality", 80)
data = _webp.WebPEncodeRGB(im.tostring(), im.size[0], im.size[1], im.size[0] * 3, float(quality))
data = _webp.WebPEncodeRGB(im.tobytes(), im.size[0], im.size[1], im.size[0] * 3, float(quality))
fp.write(data)
Image.register_open("WEBP", WebPImageFile, _accept)

Binary file not shown.

Binary file not shown.

43
Tests/test_file_webp.py Normal file
View File

@ -0,0 +1,43 @@
from tester import *
from PIL import Image
def test_read():
""" Can we write a webp without error. Does it have the bits we expect?"""
file = "Images/lena.webp"
im = Image.open(file)
assert_equal(im.mode, "RGB")
assert_equal(im.size, (128, 128))
assert_equal(im.format, "WEBP")
assert_no_exception(lambda: im.load())
assert_no_exception(lambda: im.getdata())
orig_bytes = im.tobytes()
# generated with: dwebp -ppm ../../Images/lena.webp -o lena_webp_bits.ppm
target = Image.open('Tests/images/lena_webp_bits.ppm')
assert_image_equal(im, target)
def test_write():
""" Can we write a webp without error. Does it have the bits we expect?"""
file = tempfile("temp.webp")
lena("RGB").save(file)
im= Image.open(file)
im.load()
assert_equal(im.mode, "RGB")
assert_equal(im.size, (128, 128))
assert_equal(im.format, "WEBP")
assert_no_exception(lambda: im.load())
assert_no_exception(lambda: im.getdata())
# generated with: dwebp -ppm temp.webp -o lena_webp_write.ppm
target = Image.open('Tests/images/lena_webp_write.ppm')
assert_image_equal(im, target)