From 58c5e72cdee1087d200d0c809e92c35ddeb6ad28 Mon Sep 17 00:00:00 2001 From: zuber Date: Wed, 16 Sep 2009 13:23:30 +0200 Subject: [PATCH] =?utf8?q?Dodanie=20skryptu=20do=20przycinania=20obrazk?= =?utf8?q?=C3=B3w.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- crop.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 crop.py diff --git a/crop.py b/crop.py new file mode 100755 index 00000000..a7d83840 --- /dev/null +++ b/crop.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +import sys +import os +from os.path import splitext, dirname, basename, realpath +from PIL import Image + + +def crop(image, top=0, right=0, bottom=0, left=0): + width, height = image.size + if top < 1: + top = int(height * top) + if right < 1: + right = int(width * right) + if bottom < 1: + bottom = int(height * bottom) + if left < 1: + left = int(width * left) + + bounds = (int(left), int(top), int(width - right), int(height - bottom)) + image = image.crop(bounds) + image.load() + return image + + +output_dir = realpath(os.getcwd()) + '/output' +bounds = [float(i) for i in sys.argv[1].split(':')] + +for file_name in sys.argv[2:]: + base_name, ext = splitext(file_name) + try: + image = Image.open(file_name) + except IOError, e: + sys.stderr.write('\nerror:%s:%s\n' % (file_name, e.message)) + continue + + image = crop(image, *bounds) + image.save(output_dir + '/' + basename(file_name)) \ No newline at end of file -- 2.20.1