mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
commit
79ca29f2f5
|
@ -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)
|
||||
|
|
BIN
Tests/images/lena_webp_bits.ppm
Normal file
BIN
Tests/images/lena_webp_bits.ppm
Normal file
Binary file not shown.
BIN
Tests/images/lena_webp_write.ppm
Normal file
BIN
Tests/images/lena_webp_write.ppm
Normal file
Binary file not shown.
43
Tests/test_file_webp.py
Normal file
43
Tests/test_file_webp.py
Normal 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)
|
||||
|
Loading…
Reference in New Issue
Block a user