2 # -*- coding: utf-8 -*-
4 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
5 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
9 from os.path import splitext, dirname, basename, realpath
13 def crop(image, top=0, right=0, bottom=0, left=0):
14 width, height = image.size
16 top = int(height * top)
18 right = int(width * right)
20 bottom = int(height * bottom)
22 left = int(width * left)
24 bounds = (int(left), int(top), int(width - right), int(height - bottom))
25 image = image.crop(bounds)
29 output_dir = realpath(os.getcwd()) + '/output'
30 bounds = [float(i) for i in sys.argv[1].split(':')]
32 for file_name in sys.argv[2:]:
33 base_name, ext = splitext(file_name)
35 image = Image.open(file_name)
37 sys.stderr.write('\nerror:%s:%s\n' % (file_name, e.message))
40 image = crop(image, *bounds)
41 image.save(output_dir + '/' + basename(file_name))