mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-13 05:06:49 +03:00
Allow append_images to set .icns scaled images
This commit is contained in:
parent
4247de3604
commit
2123dd70fb
|
@ -22,8 +22,7 @@ class TestFileIcns(PillowTestCase):
|
||||||
self.assertEqual(im.size, (1024, 1024))
|
self.assertEqual(im.size, (1024, 1024))
|
||||||
self.assertEqual(im.format, "ICNS")
|
self.assertEqual(im.format, "ICNS")
|
||||||
|
|
||||||
@unittest.skipIf(sys.platform != 'darwin',
|
@unittest.skipIf(sys.platform != 'darwin', "requires MacOS")
|
||||||
"requires MacOS")
|
|
||||||
def test_save(self):
|
def test_save(self):
|
||||||
im = Image.open(TEST_FILE)
|
im = Image.open(TEST_FILE)
|
||||||
|
|
||||||
|
@ -36,6 +35,22 @@ class TestFileIcns(PillowTestCase):
|
||||||
self.assertEqual(reread.size, (1024, 1024))
|
self.assertEqual(reread.size, (1024, 1024))
|
||||||
self.assertEqual(reread.format, "ICNS")
|
self.assertEqual(reread.format, "ICNS")
|
||||||
|
|
||||||
|
@unittest.skipIf(sys.platform != 'darwin', "requires MacOS")
|
||||||
|
def test_save_append_images(self):
|
||||||
|
im = Image.open(TEST_FILE)
|
||||||
|
|
||||||
|
temp_file = self.tempfile("temp.icns")
|
||||||
|
provided_im = Image.new('RGBA', (32, 32), (255, 0, 0, 0))
|
||||||
|
im.save(temp_file, append_images=[provided_im])
|
||||||
|
|
||||||
|
reread = Image.open(temp_file)
|
||||||
|
self.assert_image_equal(reread, im)
|
||||||
|
|
||||||
|
reread = Image.open(temp_file)
|
||||||
|
reread.size = (16, 16, 2)
|
||||||
|
reread.load()
|
||||||
|
self.assert_image_equal(reread, provided_im)
|
||||||
|
|
||||||
def test_sizes(self):
|
def test_sizes(self):
|
||||||
# Check that we can load all of the sizes, and that the final pixel
|
# Check that we can load all of the sizes, and that the final pixel
|
||||||
# dimensions are as expected
|
# dimensions are as expected
|
||||||
|
|
|
@ -310,6 +310,8 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
# create the temporary set of pngs
|
# create the temporary set of pngs
|
||||||
iconset = tempfile.mkdtemp('.iconset')
|
iconset = tempfile.mkdtemp('.iconset')
|
||||||
|
provided_images = {im.width:im for im in
|
||||||
|
im.encoderinfo.get("append_images", [])}
|
||||||
last_w = None
|
last_w = None
|
||||||
for w in [16, 32, 128, 256, 512]:
|
for w in [16, 32, 128, 256, 512]:
|
||||||
prefix = 'icon_{}x{}'.format(w, w)
|
prefix = 'icon_{}x{}'.format(w, w)
|
||||||
|
@ -318,10 +320,12 @@ def _save(im, fp, filename):
|
||||||
if last_w == w:
|
if last_w == w:
|
||||||
shutil.copyfile(second_path, first_path)
|
shutil.copyfile(second_path, first_path)
|
||||||
else:
|
else:
|
||||||
im.resize((w, w), Image.LANCZOS).save(first_path)
|
im_w = provided_images.get(w, im.resize((w, w), Image.LANCZOS))
|
||||||
|
im_w.save(first_path)
|
||||||
|
|
||||||
second_path = os.path.join(iconset, prefix+'@2x.png')
|
second_path = os.path.join(iconset, prefix+'@2x.png')
|
||||||
im.resize((w*2, w*2), Image.LANCZOS).save(second_path)
|
im_w2 = provided_images.get(w*2, im.resize((w*2, w*2), Image.LANCZOS))
|
||||||
|
im_w2.save(second_path)
|
||||||
last_w = w*2
|
last_w = w*2
|
||||||
|
|
||||||
# iconutil -c icns -o {} {}
|
# iconutil -c icns -o {} {}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user