else/Toolbox/crop.py
Ethan Dalool b5a1649bc0 else
2017-11-03 12:50:16 -07:00

21 lines
477 B
Python

import os
import sys
from PIL import Image
filename = sys.argv[1]
(name, extension) = os.path.splitext(filename)
newname = '%s_cropped%s' % (name, extension)
crops = sys.argv[2:]
crops = ' '.join(crops)
crops = crops.replace(',', ' ')
crops = crops.replace(' ', ' ')
crops = crops.split(' ')
crops = [int(x) for x in crops]
crops = list(crops)
print(crops)
i = Image.open(filename)
if len(crops) == 2:
crops.extend(i.size)
i = i.crop(crops)
i.save(newname, quality=100)