mirror of
https://github.com/TrentSPalmer/flask_photo_scaling_app.git
synced 2024-11-16 22:41:29 -08:00
27 lines
888 B
Python
27 lines
888 B
Python
#!/usr/bin/env python3
|
|
|
|
from PIL import Image
|
|
import os
|
|
|
|
|
|
def crop_photo(photo, photo_save_path):
|
|
photo_1280 = '1280_' + photo
|
|
photo_480 = '480_' + photo
|
|
processing_tuple = ((1280, photo_1280), (480, photo_480))
|
|
os.chdir(photo_save_path)
|
|
img = Image.open('raw_' + photo)
|
|
if img.size[0] > img.size[1]:
|
|
for x in processing_tuple:
|
|
basewidth = x[0]
|
|
wpercent = (basewidth / float(img.size[0]))
|
|
hsize = int(float(img.size[1] * float(wpercent)))
|
|
img = img.resize((basewidth, hsize), Image.ANTIALIAS)
|
|
img.save(x[1])
|
|
else:
|
|
for x in processing_tuple:
|
|
baseheight = x[0]
|
|
hpercent = (baseheight / float(img.size[1]))
|
|
wsize = int(float(img.size[0] * float(hpercent)))
|
|
img = img.resize((wsize, baseheight), Image.ANTIALIAS)
|
|
img.save(x[1])
|