From 88769d0e749ae2d0704386cca8876092c500e348 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 18 Mar 2014 19:47:22 +0000 Subject: [PATCH] fix vipsthumbnail crop with very non-square images thanks Alessandro --- tools/vipsthumbnail.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/vipsthumbnail.c b/tools/vipsthumbnail.c index f7150551..69b1b8ed 100644 --- a/tools/vipsthumbnail.c +++ b/tools/vipsthumbnail.c @@ -152,13 +152,19 @@ calculate_shrink( int width, int height, double *residual ) int shrink = floor( factor2 ); if( residual ) { - /* Width after int shrink. + /* Size after int shrink. We have to try with both axes since + * if they are very different sizes we'll see different + * rounding errors. */ int iwidth = width / shrink; + int iheight = height / shrink; /* Therefore residual scale factor is. */ - *residual = (width / factor) / iwidth; + double hresidual = (width / factor) / iwidth; + double vresidual = (height / factor) / iheight; + + *residual = VIPS_MAX( hresidual, vresidual ); } return( shrink );