From 80dcd225cbc0551b46fec6ce3d56ea3243d46a0f Mon Sep 17 00:00:00 2001 From: age Date: Thu, 22 Feb 2007 00:15:08 +0000 Subject: [PATCH] * bilder mit korrektem seitenverhaeltnis aendern --- gallery.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gallery.py b/gallery.py index 308b841..792b2f1 100755 --- a/gallery.py +++ b/gallery.py @@ -89,6 +89,19 @@ def resize_images (args): % (filename, w,h, x,y) ) im2.save(filename) +def resize_images_aspectratio (args): + x = int(args[0]) + args = args[1:] ; args.sort() + for filename in args: + im = Image.open(filename) + w,h = im.size + y = x*h/w + im2 = im.resize((x,y)) + print >>sys.stderr, ('%s: was %i,%i; resizing to %i,%i' + % (filename, w,h, x,y) ) + im2.save(filename) + + def main (): opts, args = getopt.getopt(sys.argv[1:], @@ -96,6 +109,7 @@ def main (): ['help', 'html', 'resize', + 'resize-ratio', 'size', 'thumbnail', 'rotate']) @@ -111,8 +125,7 @@ def main (): # Ensure that exactly one option is supplied if len(opts) == 0: print >> sys.stderr, ("%s: must specify one of --size, --help" - "\n --html, --resize, --thumbnail --rotate" % - sys.argv[0] ) + "\n --html, --resize, --resize-ratio, --thumbnail --rotate" % sys.argv[0] ) sys.exit(0) elif len(opts) > 1: print >> sys.stderr, ("%s: cannot specify multiple options" % @@ -125,6 +138,8 @@ def main (): output_html(args) elif opt == '--resize': resize_images(args) + elif opt == '--resize-ratio': + resize_images_aspectratio(args) elif opt == '--rotate': rotate_images(args) elif opt == '--size':