mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-13 13:16:52 +03:00
b4735f7829
Pillow now uses the webpmux library to envelop the webp images in RIFF. This allows for easy support of exif and icc_profile metadata. Also included tests that verify compatibility with jpeg for exif and icc_profile metadata. If the user does not have webp with webpmux enabled, pillow will fall back to the previous approach, meaning no exif or icc_profile metadata will be read or written to.
86 lines
1.9 KiB
Python
86 lines
1.9 KiB
Python
from tester import *
|
|
|
|
from PIL import Image
|
|
|
|
try:
|
|
from PIL import _webp
|
|
if not _webp.HAVE_WEBPMUX:
|
|
skip('webpmux support not installed')
|
|
except:
|
|
skip('webp support not installed')
|
|
|
|
try:
|
|
from StringIO import StringIO
|
|
except ImportError:
|
|
from io import StringIO
|
|
|
|
|
|
def test_read_exif_metadata():
|
|
|
|
file_path = "Images/flower.webp"
|
|
image = Image.open(file_path)
|
|
|
|
assert_equal(image.format, "WEBP")
|
|
exif_data = image.info.get("exif", None)
|
|
assert_true(exif_data)
|
|
|
|
exif = image._getexif()
|
|
|
|
#camera make
|
|
assert_equal(exif[271], "Canon")
|
|
|
|
jpeg_image = Image.open('Tests/images/flower.jpg')
|
|
expected_exif = jpeg_image.info['exif']
|
|
|
|
assert_equal(exif_data, expected_exif)
|
|
|
|
|
|
def test_write_exif_metadata():
|
|
file_path = "Tests/images/flower.jpg"
|
|
image = Image.open(file_path)
|
|
expected_exif = image.info['exif']
|
|
|
|
buffer = StringIO()
|
|
|
|
image.save(buffer, "webp", exif=expected_exif)
|
|
|
|
buffer.seek(0)
|
|
webp_image = Image.open(buffer)
|
|
|
|
webp_exif = webp_image.info.get('exif', None)
|
|
assert_true(webp_exif)
|
|
assert_equal(webp_exif, expected_exif)
|
|
|
|
|
|
def test_read_icc_profile():
|
|
|
|
file_path = "Images/flower2.webp"
|
|
image = Image.open(file_path)
|
|
|
|
assert_equal(image.format, "WEBP")
|
|
assert_true(image.info.get("icc_profile", None))
|
|
|
|
icc = image.info['icc_profile']
|
|
|
|
jpeg_image = Image.open('Tests/images/flower2.jpg')
|
|
expected_icc = jpeg_image.info['icc_profile']
|
|
|
|
assert_equal(icc, expected_icc)
|
|
|
|
|
|
def test_write_icc_metadata():
|
|
file_path = "Tests/images/flower2.jpg"
|
|
image = Image.open(file_path)
|
|
expected_icc_profile = image.info['icc_profile']
|
|
|
|
buffer = StringIO()
|
|
|
|
image.save(buffer, "webp", icc_profile=expected_icc_profile)
|
|
|
|
buffer.seek(0)
|
|
webp_image = Image.open(buffer)
|
|
|
|
webp_icc_profile = webp_image.info.get('icc_profile', None)
|
|
assert_true(webp_icc_profile)
|
|
assert_equal(webp_icc_profile, expected_icc_profile)
|