Skip to content

Commit

Permalink
Update kang.py (UsergeTeam#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
nealgosalia authored Jul 26, 2020
1 parent 0fd55e5 commit 8da972d
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions userge/plugins/fun/kang.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# All rights reserved.

import os
import math
import random
import urllib.request

Expand Down Expand Up @@ -209,21 +208,10 @@ def resize_photo(photo: str) -> str:
""" Resize the given photo to 512x512 """
image = Image.open(photo)
maxsize = (512, 512)
if (image.width and image.height) < 512:
size1 = image.width
size2 = image.height
if image.width > image.height:
scale = 512 / size1
size1new = 512
size2new = size2 * scale
else:
scale = 512 / size2
size1new = size1 * scale
size2new = 512
size1new = math.floor(size1new)
size2new = math.floor(size2new)
sizenew = (size1new, size2new)
image = image.resize(sizenew)
if max(image.width, image.height) < 512:
scale = 512 / max(image.width, image.height)
new_size = (int(image.width * scale), int(image.height * scale))
image = image.resize(new_size, Image.ANTIALIAS)
else:
image.thumbnail(maxsize)
os.remove(photo)
Expand Down

0 comments on commit 8da972d

Please sign in to comment.