mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
Merge pull request #1909 from uploadcare/png-icc-profile
Get ICC profile from `encoderinfo` while PNG saving
This commit is contained in:
commit
6a3acde001
|
@ -755,8 +755,8 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
|
|||
for cid, data in info.chunks:
|
||||
chunk(fp, cid, data)
|
||||
|
||||
# ICC profile writing support -- 2008-06-06 Florian Hoech
|
||||
if im.info.get("icc_profile"):
|
||||
icc = im.encoderinfo.get("icc_profile", im.info.get("icc_profile"))
|
||||
if icc:
|
||||
# ICC profile
|
||||
# according to PNG spec, the iCCP chunk contains:
|
||||
# Profile name 1-79 bytes (character string)
|
||||
|
@ -764,7 +764,7 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
|
|||
# Compression method 1 byte (0)
|
||||
# Compressed profile n bytes (zlib with deflate compression)
|
||||
name = b"ICC Profile"
|
||||
data = name + b"\0\0" + zlib.compress(im.info["icc_profile"])
|
||||
data = name + b"\0\0" + zlib.compress(icc)
|
||||
chunk(fp, b"iCCP", data)
|
||||
|
||||
ImageFile._save(im, _idat(fp, chunk),
|
||||
|
|
BIN
Tests/images/icc_profile.png
Normal file
BIN
Tests/images/icc_profile.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
|
@ -434,26 +434,36 @@ class TestFilePng(PillowTestCase):
|
|||
|
||||
self.assertEqual(im.info["transparency"], 0)
|
||||
|
||||
def test_save_icc_profile_none(self):
|
||||
# check saving files with an ICC profile set to None (omit profile)
|
||||
in_file = "Tests/images/icc_profile_none.png"
|
||||
im = Image.open(in_file)
|
||||
def test_save_icc_profile(self):
|
||||
im = Image.open("Tests/images/icc_profile_none.png")
|
||||
self.assertEqual(im.info['icc_profile'], None)
|
||||
|
||||
with_icc = Image.open("Tests/images/icc_profile.png")
|
||||
expected_icc = with_icc.info['icc_profile']
|
||||
|
||||
im = roundtrip(im, icc_profile=expected_icc)
|
||||
self.assertEqual(im.info['icc_profile'], expected_icc)
|
||||
|
||||
def test_discard_icc_profile(self):
|
||||
im = Image.open('Tests/images/icc_profile.png')
|
||||
|
||||
im = roundtrip(im, icc_profile=None)
|
||||
self.assertNotIn('icc_profile', im.info)
|
||||
|
||||
def test_roundtrip_icc_profile(self):
|
||||
im = Image.open('Tests/images/icc_profile.png')
|
||||
expected_icc = im.info['icc_profile']
|
||||
|
||||
im = roundtrip(im)
|
||||
self.assertEqual(im.info['icc_profile'], expected_icc)
|
||||
|
||||
def test_roundtrip_no_icc_profile(self):
|
||||
im = Image.open("Tests/images/icc_profile_none.png")
|
||||
self.assertEqual(im.info['icc_profile'], None)
|
||||
|
||||
im = roundtrip(im)
|
||||
self.assertNotIn('icc_profile', im.info)
|
||||
|
||||
def test_roundtrip_icc_profile(self):
|
||||
# check that we can roundtrip the icc profile
|
||||
im = hopper('RGB')
|
||||
|
||||
jpeg_image = Image.open('Tests/images/flower2.jpg')
|
||||
expected_icc = jpeg_image.info['icc_profile']
|
||||
|
||||
im.info['icc_profile'] = expected_icc
|
||||
im = roundtrip(im)
|
||||
self.assertEqual(im.info['icc_profile'], expected_icc)
|
||||
|
||||
def test_repr_png(self):
|
||||
im = hopper()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user