From 63f6e94be40bab534070840222b228db4efc133c Mon Sep 17 00:00:00 2001 From: hugovk Date: Thu, 23 Apr 2015 13:25:45 +0300 Subject: [PATCH] Flake8 after PR #1185 --- PIL/IcnsImagePlugin.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/PIL/IcnsImagePlugin.py b/PIL/IcnsImagePlugin.py index c185277ba..a1ebee704 100644 --- a/PIL/IcnsImagePlugin.py +++ b/PIL/IcnsImagePlugin.py @@ -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") \ No newline at end of file + os.startfile("out.png")