Merge pull request #3004 from radarhere/icns

Fix and improve efficient saving of ICNS on macOS
This commit is contained in:
Hugo 2018-03-12 22:09:42 +02:00 committed by GitHub
commit caf3ec5b04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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