From 6558af03817fda7ab8b3b89c36b77a4df061502b Mon Sep 17 00:00:00 2001 From: Brian Mattern Date: Mon, 26 Mar 2012 16:47:42 -0700 Subject: [PATCH] simplify preserve_orientation code remove unneeded parameter --- hyde/ext/plugins/images.py | 20 +++++-------------- hyde/tests/ext/test_images.py | 36 ----------------------------------- 2 files changed, 5 insertions(+), 51 deletions(-) diff --git a/hyde/ext/plugins/images.py b/hyde/ext/plugins/images.py index cc3ffd4..e5215e2 100644 --- a/hyde/ext/plugins/images.py +++ b/hyde/ext/plugins/images.py @@ -157,24 +157,14 @@ def scale_aspect(a, b1, b2): return int(ceil(a * b2 / float(b1))) -def thumb_scale_size(orig_width, orig_height, dim1, dim2, preserve_orientation=False): +def thumb_scale_size(orig_width, orig_height, width, height): """ - Determine thumbnail size + Determine size to scale to scale for thumbnailst Params Params: orig_width, orig_height: original image dimensions - dim1, dim2: thumbnail dimensions - preserve_orientatin: whether to preserve original image's orientation - - If `preserve_orientation` is True and the original image is portrait, then - dim1 corresponds to the height and dim2 corresponds to the width - Otherwise, dim1 is width and dim2 is height. + width, height: thumbnail dimensions """ - if preserve_orientation and orig_height > orig_width: - width, height = dim2, dim1 - else: - width, height = dim1, dim2 - if width is None: width = scale_aspect(orig_width, orig_height, height) elif height is None: @@ -256,11 +246,11 @@ class ImageThumbnailsPlugin(Plugin): if im.mode != 'RGBA': im = im.convert('RGBA') - resize_width, resize_height = thumb_scale_size(im.size[0], im.size[1], width, height, preserve_orientation) - if preserve_orientation and im.size[1] > im.size[0]: width, height = height, width + resize_width, resize_height = thumb_scale_size(im.size[0], im.size[1], width, height) + self.logger.debug("Resize to: %d,%d" % (resize_width, resize_height)) im = im.resize((resize_width, resize_height), Image.ANTIALIAS) if width is not None and height is not None: diff --git a/hyde/tests/ext/test_images.py b/hyde/tests/ext/test_images.py index 1c620f6..80d9522 100644 --- a/hyde/tests/ext/test_images.py +++ b/hyde/tests/ext/test_images.py @@ -181,42 +181,6 @@ class TestImageThumbSize(object): assert nw == 100 assert nh == 50 - def test_larger_only_portrait(self): - ow, oh = 100, 200 - nw, nh = thumb_scale_size(ow, oh, 50, None, True) - assert nw == 25 - assert nh == 50 - - def test_larger_only_landscape(self): - ow, oh = 200, 100 - nw, nh = thumb_scale_size(ow, oh, 50, None, True) - assert nw == 50 - assert nh == 25 - - def test_smaller_only_portrait(self): - ow, oh = 100, 200 - nw, nh = thumb_scale_size(ow, oh, None, 50, True) - assert nw == 50 - assert nh == 100 - - def test_smaller_only_landscape(self): - ow, oh = 200, 100 - nw, nh = thumb_scale_size(ow, oh, None, 50, True) - assert nw == 100 - assert nh == 50 - - def test_larger_and_smaller_portrait(self): - ow, oh = 100, 200 - nw, nh = thumb_scale_size(ow, oh, 100, 50, True) - assert nw == 50 - assert nh == 100 - - def test_larger_and_smaller_landscape(self): - ow, oh = 200, 100 - nw, nh = thumb_scale_size(ow, oh, 100, 50, True) - assert nw == 100 - assert nh == 50 - class TestImageThumbnails(object): def setUp(self):