Skip to content

Commit

Permalink
Fix #317
Browse files Browse the repository at this point in the history
Crop images to square form before making thumbnail, not square images cause issues on Windows
  • Loading branch information
DarkFenX committed Jul 8, 2015
1 parent e63c354 commit 5ac3192
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions scripts/icons_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ def unzero(fname):
fnames.add(fname)


def crop_image(img):
w, h = img.size
if h == w:
return img
normal = min(h, w)
diff_w = w - normal
diff_h = h - normal
crop_top = diff_h // 2
crop_bot = diff_h // 2 + diff_h % 2
crop_left = diff_w // 2
crop_right = diff_w // 2 + diff_w % 2
box = (crop_left, crop_top, w - crop_right, h - crop_bot)
return img.crop(box)


def get_icon_file(request):
"""
Get the iconFile field value and find proper
Expand All @@ -190,6 +205,7 @@ def get_icon_file(request):
except KeyError:
fullpath = sizes[max(sizes)]
img = Image.open(fullpath)
img = crop_image(img)
img.thumbnail(ICON_SIZE, Image.ANTIALIAS)
else:
img = Image.open(fullpath)
Expand Down
16 changes: 16 additions & 0 deletions scripts/renders_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,27 @@
toadd = needed.difference(existing)


def crop_image(img):
w, h = img.size
if h == w:
return img
normal = min(h, w)
diff_w = w - normal
diff_h = h - normal
crop_top = diff_h // 2
crop_bot = diff_h // 2 + diff_h % 2
crop_left = diff_w // 2
crop_right = diff_w // 2 + diff_w % 2
box = (crop_left, crop_top, w - crop_right, h - crop_bot)
return img.crop(box)


def get_render(type_id):
fname = '{}.png'.format(type_id)
fullpath = os.path.join(export_dir, fname)
img = Image.open(fullpath)
if img.size != RENDER_SIZE:
img = crop_image(img)
img.thumbnail(RENDER_SIZE, Image.ANTIALIAS)
return img

Expand Down
Binary file modified staticdata/icons/icon107_12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified staticdata/icons/icon109_64_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified staticdata/icons/icon109_64_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5ac3192

Please sign in to comment.