Merge pull request #1208 from hugovk/1185

Flake8 after PR #1185
This commit is contained in:
Hugo 2015-04-23 13:45:37 +03:00
commit 40165d6860

View File

@ -17,8 +17,11 @@
from PIL import Image, ImageFile, PngImagePlugin, _binary
import io
import os
import shutil
import struct
import tempfile, shutil, os, sys
import sys
import tempfile
enable_jpeg2k = hasattr(Image.core, 'jp2klib_version')
if enable_jpeg2k:
@ -294,40 +297,41 @@ class IcnsImageFile(ImageFile.ImageFile):
self.tile = ()
self.load_end()
def _save(im, fp, filename):
"""
Saves the image as a series of PNG files,
that are then converted to a .icns file
using the OS X command line utility 'iconutil'.
OS X only.
"""
try:
fp.flush()
except:
pass
# create the temporary set of pngs
iconset = tempfile.mkdtemp('.iconset')
last_w = None
last_im = None
for w in [16,32,128,256,512]:
prefix = 'icon_{}x{}'.format(w,w)
for w in [16, 32, 128, 256, 512]:
prefix = 'icon_{}x{}'.format(w, w)
if last_w == w:
im_scaled = last_im
else:
im_scaled = im.resize((w,w), Image.LANCZOS)
im_scaled = im.resize((w, w), Image.LANCZOS)
im_scaled.save(os.path.join(iconset, prefix+'.png'))
im_scaled = im.resize((w*2,w*2), Image.LANCZOS)
im_scaled = im.resize((w*2, w*2), Image.LANCZOS)
im_scaled.save(os.path.join(iconset, prefix+'@2x.png'))
last_im = im_scaled
# iconutil -c icns -o {} {}
from subprocess import Popen, PIPE, CalledProcessError
convert_cmd = ["iconutil","-c","icns","-o",filename,iconset]
convert_cmd = ["iconutil", "-c", "icns", "-o", filename, iconset]
stderr = tempfile.TemporaryFile()
convert_proc = Popen(convert_cmd, stdout=PIPE, stderr=stderr)
@ -337,7 +341,7 @@ def _save(im, fp, filename):
# remove the temporary files
shutil.rmtree(iconset)
if retcode:
raise CalledProcessError(retcode, convert_cmd)
@ -360,4 +364,4 @@ if __name__ == '__main__':
im = Image.open(open(sys.argv[1], "rb"))
im.save("out.png")
if sys.platform == 'windows':
os.startfile("out.png")
os.startfile("out.png")