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)
30 output_dir = realpath(os.getcwd()) + '/output'
31 bounds = [float(i) for i in sys.argv[1].split(':')]
33 for file_name in sys.argv[2:]:
34 base_name, ext = splitext(file_name)
36 image = Image.open(file_name)
38 sys.stderr.write('\nerror:%s:%s\n' % (file_name, e.message))
41 image = crop(image, *bounds)
42 image.save(output_dir + '/' + basename(file_name))