fix thumbnail with small plus crop plus no upsize

thumbnail could fail for small images if upsize was disallowed and crop
was enabled, thanks Andrewsville

see https://github.com/libvips/libvips/issues/2157
This commit is contained in:
John Cupitt 2021-07-18 15:00:35 +01:00
parent dd4b11063a
commit 2041f228f5
2 changed files with 9 additions and 3 deletions

View File

@ -1,6 +1,7 @@
14/6/21 started 8.12
- all tools support `--version`
- add vips_svgload_string() convenience function
- fix thumbnail with small image plus crop plus no upsize [Andrewsville]
14/7/21 started 8.11.3
- build threadpool later [kleisauke]

View File

@ -928,8 +928,13 @@ vips_thumbnail_build( VipsObject *object )
/* Crop after rotate so we don't need to rotate the crop box.
*/
if( thumbnail->crop != VIPS_INTERESTING_NONE ) {
g_info( "cropping to %dx%d",
thumbnail->width, thumbnail->height );
/* The image can be smaller than the target. Adjust the
* arguments to vips_smartcrop().
*/
int crop_width = VIPS_MIN( thumbnail->width, in->Xsize );
int crop_height = VIPS_MIN( thumbnail->height, in->Ysize );
g_info( "cropping to %dx%d", crop_width, crop_height );
/* Need to copy to memory, we have to stay seq.
*
@ -937,7 +942,7 @@ vips_thumbnail_build( VipsObject *object )
*/
if( !(t[8] = vips_image_copy_memory( in )) ||
vips_smartcrop( t[8], &t[11],
thumbnail->width, thumbnail->height,
crop_width, crop_height,
"interesting", thumbnail->crop,
NULL ) )
return( -1 );