Skip to content

Commit

Permalink
Default height to VIPS_MAX_COORD for vips_thumbnail
Browse files Browse the repository at this point in the history
This is to prevent reduction in the vertical axis when the height is omitted.

See: kleisauke/net-vips#71.
  • Loading branch information
kleisauke committed May 3, 2020
1 parent 54bfa23 commit 2f57ea8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 4 additions & 5 deletions libvips/resample/thumbnail.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* - smarter heif thumbnail selection
* 12/10/19
* - add thumbnail_source
* 3/5/20 kleisauke
* - prevent reduction in the vertical axis when the height is omitted
*/

/*
Expand Down Expand Up @@ -560,9 +562,6 @@ vips_thumbnail_build( VipsObject *object )
if( vips_object_argument_isset( object, "no_rotate" ) )
thumbnail->auto_rotate = !thumbnail->no_rotate;

if( !vips_object_argument_isset( object, "height" ) )
thumbnail->height = thumbnail->width;

/* Open and do any pre-shrinking.
*/
if( !(t[0] = vips_thumbnail_open( thumbnail )) )
Expand Down Expand Up @@ -825,7 +824,7 @@ vips_thumbnail_class_init( VipsThumbnailClass *class )
_( "Size to this height" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsThumbnail, height ),
1, VIPS_MAX_COORD, 1 );
1, VIPS_MAX_COORD, VIPS_MAX_COORD );

VIPS_ARG_ENUM( class, "size", 114,
_( "size" ),
Expand Down Expand Up @@ -895,7 +894,7 @@ static void
vips_thumbnail_init( VipsThumbnail *thumbnail )
{
thumbnail->width = 1;
thumbnail->height = 1;
thumbnail->height = VIPS_MAX_COORD;
thumbnail->auto_rotate = TRUE;
thumbnail->intent = VIPS_INTENT_RELATIVE;
}
Expand Down
10 changes: 5 additions & 5 deletions test/test-suite/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_shrink(self):
def test_thumbnail(self):
im = pyvips.Image.thumbnail(JPEG_FILE, 100)

assert im.height == 100
assert im.width == 100
assert im.bands == 3
assert im.bands == 3

Expand All @@ -142,9 +142,9 @@ def test_thumbnail(self):
assert abs(im_orig.avg() - im.avg()) < 1

# make sure we always get the right width
for height in range(440, 1, -13):
im = pyvips.Image.thumbnail(JPEG_FILE, height)
assert im.height == height
for width in range(440, 1, -13):
im = pyvips.Image.thumbnail(JPEG_FILE, width)
assert im.width == width

# should fit one of width or height
im = pyvips.Image.thumbnail(JPEG_FILE, 100, height=300)
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_thumbnail(self):

# thumb should be portrait
assert thumb.width < thumb.height
assert thumb.height == 100
assert thumb.width == 100

def test_similarity(self):
im = pyvips.Image.new_from_file(JPEG_FILE)
Expand Down

0 comments on commit 2f57ea8

Please sign in to comment.