Browse Source

simplify preserve_orientation code

remove unneeded parameter
main
Brian Mattern 12 years ago
committed by Lakshmi Vyasarajan
parent
commit
6558af0381
2 changed files with 5 additions and 51 deletions
  1. +5
    -15
      hyde/ext/plugins/images.py
  2. +0
    -36
      hyde/tests/ext/test_images.py

+ 5
- 15
hyde/ext/plugins/images.py View File

@@ -157,24 +157,14 @@ def scale_aspect(a, b1, b2):
return int(ceil(a * b2 / float(b1))) 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: Params:
orig_width, orig_height: original image dimensions 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: if width is None:
width = scale_aspect(orig_width, orig_height, height) width = scale_aspect(orig_width, orig_height, height)
elif height is None: elif height is None:
@@ -256,11 +246,11 @@ class ImageThumbnailsPlugin(Plugin):
if im.mode != 'RGBA': if im.mode != 'RGBA':
im = im.convert('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]: if preserve_orientation and im.size[1] > im.size[0]:
width, height = height, width 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)) self.logger.debug("Resize to: %d,%d" % (resize_width, resize_height))
im = im.resize((resize_width, resize_height), Image.ANTIALIAS) im = im.resize((resize_width, resize_height), Image.ANTIALIAS)
if width is not None and height is not None: if width is not None and height is not None:


+ 0
- 36
hyde/tests/ext/test_images.py View File

@@ -181,42 +181,6 @@ class TestImageThumbSize(object):
assert nw == 100 assert nw == 100
assert nh == 50 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): class TestImageThumbnails(object):


def setUp(self): def setUp(self):


Loading…
Cancel
Save