changeset 1:c5d30bfd032e

remove utils, this now lives in cropresize: http://k0s.org/hg/cropresize/
author k0s <k0scist@gmail.com>
date Tue, 15 Dec 2009 21:04:17 -0500
parents b7348ffe5b46
children 4b8aa9b0a45b
files montage/utils.py
diffstat 1 files changed, 0 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/montage/utils.py	Mon Sep 07 15:38:38 2009 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-#!/usr/bin/env python
-
-import os
-
-from PIL import Image
-
-def crop_resize(image, size):
-    """crop out the proportional middle of the image and set to the desired size"""
-    assert size[0] or size[1]
-
-    size = list(size)
-
-    if size[0] > image.size[0]:
-        return image
-    if size[1] > image.size[1]:
-        return image
-
-    image_ar = image.size[0]/float(image.size[1])
-    crop = not size[0] or not size[1]
-    if not size[1]:
-        size[1] = int(image.size[1]*size[0]/float(image.size[0]) )
-    if not size[0]:
-        size[0] = int(image.size[0]*size[1]/float(image.size[1]) )
-    size_ar = size[0]/float(size[1])
-                
-    if crop:
-        if image_ar > size_ar:
-            # trim the width
-            xoffset = int(0.5*(image.size[0] - size_ar*image.size[1]))
-            image = image.crop((xoffset, 0, image.size[0]-xoffset, image.size[1]))
-        elif image_ar < size_ar:
-            # trim the height
-            yoffset = int(0.5*(image.size[1] - image.size[0]/size_ar))
-            image = image.crop((0, yoffset, image.size[0], image.size[1] - yoffset))
-
-    return image.resize(size, Image.ANTIALIAS)
-
-if __name__ == '__main__':
-    from optparse import OptionParser
-    parser = OptionParser()
-    parser.add_option('-f', '--file')
-    parser.add_option('-W', '--width')
-    parser.add_option('-H', '--height')
-    (options, args) = parser.parse_args()
-
-    assert os.path.exists(options.file)
-
-    i = Image.open(options.file)
-    new_image = crop_resize(i, (int(options.width), int(options.height)))
-    new_image.show()