mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 09:44:31 +03:00
Merge branch 'master' of https://github.com/wiredfool/Pillow into readme
This commit is contained in:
commit
1713fef08f
|
@ -6,6 +6,8 @@ python:
|
||||||
- 3.2
|
- 3.2
|
||||||
- 3.3
|
- 3.3
|
||||||
|
|
||||||
|
install: "sudo apt-get -qq install libfreetype6-dev liblcms1-dev libwebp-dev"
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- python setup.py clean
|
- python setup.py clean
|
||||||
- python setup.py install
|
- python setup.py install
|
||||||
|
|
|
@ -23,7 +23,7 @@ def _save(im, fp, filename):
|
||||||
raise IOError("cannot write mode %s as WEBP" % im.mode)
|
raise IOError("cannot write mode %s as WEBP" % im.mode)
|
||||||
quality = im.encoderinfo.get("quality", 80)
|
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)
|
fp.write(data)
|
||||||
|
|
||||||
Image.register_open("WEBP", WebPImageFile, _accept)
|
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