From 5e7433ab56c195f00ab9f9baa5c7ee883a9d2915 Mon Sep 17 00:00:00 2001 From: age Date: Thu, 19 Jul 2012 22:08:01 +0000 Subject: [PATCH] minimal erweitert --- gallery.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/gallery.py b/gallery.py index 80b65f9..6dc4b18 100755 --- a/gallery.py +++ b/gallery.py @@ -17,6 +17,7 @@ Options: --html Output HTML to stdout --resize x y Resize specified images to x,y --resize-ratio x Resize specified images with correct aspect ratio + --resize-ratio-y y Resize specified images with correct aspect ratio --rotate x Rotate the image counter clockwise for x degrees --size Display the image sizes --thumbnail x y Make thumbnails of specified images, ignoring existing @@ -88,6 +89,8 @@ def resize_images (args): im2 = im.resize((x,y)) print >>sys.stderr, ('%s: was %i,%i; resizing to %i,%i' % (filename, w,h, x,y) ) + root, ext = os.path.splitext(filename) + filename = ('%s_%s%s%s%s%s') % (root, 'x', w, 'y', h , ext) im2.save(filename) def resize_images_aspectratio (args): @@ -100,6 +103,23 @@ def resize_images_aspectratio (args): im2 = im.resize((x,y)) print >>sys.stderr, ('%s: was %i,%i; resizing to %i,%i' % (filename, w,h, x,y) ) + root, ext = os.path.splitext(filename) + filename = ('%s_%s%s%s') % (root, 'x', x , ext) + im2.save(filename) + + +def resize_images_aspectratio_y (args): + y = int(args[0]) + args = args[1:] ; args.sort() + for filename in args: + im = Image.open(filename) + w,h = im.size + x = y*w/h + im2 = im.resize((x,y)) + print >>sys.stderr, ('%s: was %i,%i; resizing to %i,%i' + % (filename, w,h, x,y) ) + root, ext = os.path.splitext(filename) + filename = ('%s_%s%s%s') % (root, 'y', y , ext) im2.save(filename) @@ -111,9 +131,10 @@ def main (): 'html', 'resize', 'resize-ratio', + 'resize-ratio-y', 'size', 'thumbnail', - 'rotate']) + 'rotate']) # Remove the unused option arguments opts = [opt for opt,arg in opts] @@ -141,6 +162,8 @@ def main (): resize_images(args) elif opt == '--resize-ratio': resize_images_aspectratio(args) + elif opt == '--resize-ratio-y': + resize_images_aspectratio_y(args) elif opt == '--rotate': rotate_images(args) elif opt == '--size':