diff --git a/.travis.yml b/.travis.yml index 2ed03740b..f3f98e5d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,8 @@ python: - 3.2 - 3.3 +install: "sudo apt-get -qq install libfreetype6-dev liblcms1-dev libwebp-dev" + script: - python setup.py clean - python setup.py install diff --git a/PIL/WebPImagePlugin.py b/PIL/WebPImagePlugin.py index 628ac7ff6..9321c05f3 100644 --- a/PIL/WebPImagePlugin.py +++ b/PIL/WebPImagePlugin.py @@ -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) diff --git a/Tests/images/lena_webp_bits.ppm b/Tests/images/lena_webp_bits.ppm new file mode 100644 index 000000000..62fd9803d Binary files /dev/null and b/Tests/images/lena_webp_bits.ppm differ diff --git a/Tests/images/lena_webp_write.ppm b/Tests/images/lena_webp_write.ppm new file mode 100644 index 000000000..4fa197999 Binary files /dev/null and b/Tests/images/lena_webp_write.ppm differ diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py new file mode 100644 index 000000000..460b22d9c --- /dev/null +++ b/Tests/test_file_webp.py @@ -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) +