Skip to content

Default height to VIPS_MAX_COORD for vips_thumbnail #1639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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