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 from PIL import Image, ImageFile, PngImagePlugin, _binary
import io import io
import os
import shutil
import struct import struct
import tempfile, shutil, os, sys import sys
import tempfile
enable_jpeg2k = hasattr(Image.core, 'jp2klib_version') enable_jpeg2k = hasattr(Image.core, 'jp2klib_version')
if enable_jpeg2k: if enable_jpeg2k:
@ -294,6 +297,7 @@ class IcnsImageFile(ImageFile.ImageFile):
self.tile = () self.tile = ()
self.load_end() self.load_end()
def _save(im, fp, filename): def _save(im, fp, filename):
""" """
Saves the image as a series of PNG files, Saves the image as a series of PNG files,
@ -311,23 +315,23 @@ def _save(im, fp, filename):
iconset = tempfile.mkdtemp('.iconset') iconset = tempfile.mkdtemp('.iconset')
last_w = None last_w = None
last_im = 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)
if last_w == w: if last_w == w:
im_scaled = last_im im_scaled = last_im
else: 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.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')) im_scaled.save(os.path.join(iconset, prefix+'@2x.png'))
last_im = im_scaled last_im = im_scaled
# iconutil -c icns -o {} {} # iconutil -c icns -o {} {}
from subprocess import Popen, PIPE, CalledProcessError 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() stderr = tempfile.TemporaryFile()
convert_proc = Popen(convert_cmd, stdout=PIPE, stderr=stderr) convert_proc = Popen(convert_cmd, stdout=PIPE, stderr=stderr)