Fixed issues with 256x256 images in exes.
This commit is contained in:
parent
037230b206
commit
eb5d6d84c3
1 changed files with 18 additions and 5 deletions
23
pe.py
23
pe.py
|
|
@ -7,12 +7,25 @@ from ico_plugin import *
|
||||||
def resize(image, size, format=None):
|
def resize(image, size, format=None):
|
||||||
output = StringIO()
|
output = StringIO()
|
||||||
back = Image.new('RGBA', size, (0,0,0,0))
|
back = Image.new('RGBA', size, (0,0,0,0))
|
||||||
image.thumbnail(size, Image.ANTIALIAS)
|
|
||||||
offset = [0,0]
|
if image.size[0] < size[0] or image.size[1] < size[1]:
|
||||||
if image.size[0] >= image.size[1]:
|
if image.height > image.width:
|
||||||
offset[1] = back.size[1]/2-image.size[1]/2
|
factor = size[0] / image.height
|
||||||
|
else:
|
||||||
|
factor = size[1] / image.width
|
||||||
|
image = image.resize((int(image.width * factor), int(image.height * factor)), Image.ANTIALIAS)
|
||||||
else:
|
else:
|
||||||
offset[0] = back.size[0]/2-image.size[0]/2
|
image.thumbnail(size, Image.ANTIALIAS)
|
||||||
|
|
||||||
|
offset = [0, 0]
|
||||||
|
if image.size[0] > image.size[1]:
|
||||||
|
offset[1] = int(back.size[1]/2-image.size[1]/2)
|
||||||
|
elif image.size[0] < image.size[1]:
|
||||||
|
offset[0] = int(back.size[0]/2-image.size[0]/2)
|
||||||
|
else:
|
||||||
|
offset[0] = int(back.size[0]/2-image.size[0]/2)
|
||||||
|
offset[1] = int(back.size[1]/2-image.size[1]/2)
|
||||||
|
|
||||||
back.paste(image, tuple(offset))
|
back.paste(image, tuple(offset))
|
||||||
format = format or image.format
|
format = format or image.format
|
||||||
back.save(output, format)
|
back.save(output, format)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue