2013-03-19 22:43:45 +04:00
|
|
|
from tester import *
|
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
2013-03-20 00:40:10 +04:00
|
|
|
def test_read():
|
2013-03-20 00:49:01 +04:00
|
|
|
""" Can we write a webp without error. Does it have the bits we expect?"""
|
|
|
|
|
2013-03-19 22:43:45 +04:00
|
|
|
file = "Images/lena.webp"
|
|
|
|
im = Image.open(file)
|
|
|
|
|
|
|
|
assert_equal(im.mode, "RGB")
|
|
|
|
assert_equal(im.size, (128, 128))
|
|
|
|
assert_equal(im.format, "WEBP")
|
2013-03-20 00:40:10 +04:00
|
|
|
assert_no_exception(lambda: im.load())
|
|
|
|
assert_no_exception(lambda: im.getdata())
|
2013-03-19 22:43:45 +04:00
|
|
|
|
2013-03-20 00:40:10 +04:00
|
|
|
orig_bytes = im.tobytes()
|
2013-03-19 22:43:45 +04:00
|
|
|
|
2013-03-20 00:40:10 +04:00
|
|
|
# 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():
|
2013-03-20 00:49:01 +04:00
|
|
|
""" Can we write a webp without error. Does it have the bits we expect?"""
|
|
|
|
|
2013-03-19 22:43:45 +04:00
|
|
|
file = tempfile("temp.webp")
|
|
|
|
|
|
|
|
lena("RGB").save(file)
|
|
|
|
|
2013-03-20 00:49:01 +04:00
|
|
|
im= Image.open(file)
|
|
|
|
im.load()
|
2013-03-19 22:43:45 +04:00
|
|
|
|
2013-03-20 00:49:01 +04:00
|
|
|
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())
|
2013-03-19 22:43:45 +04:00
|
|
|
|
2013-03-20 00:49:01 +04:00
|
|
|
# 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)
|
2013-03-19 22:43:45 +04:00
|
|
|
|