mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-14 19:36:38 +03:00
Merge pull request #3004 from radarhere/icns
Fix and improve efficient saving of ICNS on macOS
This commit is contained in:
commit
caf3ec5b04
|
@ -311,19 +311,18 @@ 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')
|
||||||
last_w = None
|
last_w = None
|
||||||
last_im = 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)
|
||||||
|
|
||||||
|
first_path = os.path.join(iconset, prefix+'.png')
|
||||||
if last_w == w:
|
if last_w == w:
|
||||||
im_scaled = last_im
|
shutil.copyfile(second_path, first_path)
|
||||||
else:
|
else:
|
||||||
im_scaled = im.resize((w, w), Image.LANCZOS)
|
im.resize((w, w), Image.LANCZOS).save(first_path)
|
||||||
im_scaled.save(os.path.join(iconset, prefix+'.png'))
|
|
||||||
|
|
||||||
im_scaled = im.resize((w*2, w*2), Image.LANCZOS)
|
second_path = os.path.join(iconset, prefix+'@2x.png')
|
||||||
im_scaled.save(os.path.join(iconset, prefix+'@2x.png'))
|
im.resize((w*2, w*2), Image.LANCZOS).save(second_path)
|
||||||
last_im = im_scaled
|
last_w = w*2
|
||||||
|
|
||||||
# iconutil -c icns -o {} {}
|
# iconutil -c icns -o {} {}
|
||||||
from subprocess import Popen, PIPE, CalledProcessError
|
from subprocess import Popen, PIPE, CalledProcessError
|
||||||
|
|
Loading…
Reference in New Issue
Block a user