Sharp: .resize() crops image when crop is unnecessary

Created on 30 May 2017  路  6Comments  路  Source: lovell/sharp

I'm having trouble with resize function cropping sides of the image when only resize is needed:

// assume expressjs middleware
const resizeTransform = sharp().resize(/* either numbers or undefined-s from querystring */);
const downloadStream = request(req.query.src);
req.pipe(downloadStream).pipe(resizeTransform).pipe(res);

passing along width=200 produces this image:
image

However passing 199 or 201 produces expected result:
image-2

original:
arnold-transformation-challenge-1-600x399-1

Seems like some strange bug to me. I was expecting to always get a downscaled image in the original aspect ratio. I couldn't find anything in the documentation regarding controlling the crop. How does one achieves resizing this without cropping, and only having crop when both width and height are present?

I already tried converting to JPEG first, passing both dimensions and playing with .max, .min methods, no luck.

Running node v6.10.2, sharp v0.18.0

bug

Most helpful comment

Just checked with v0.18.1 and it works great!

All 6 comments

Hello, I'm currently investigating a problem with JPEG shrink-on-load that appears to have been introduced in v0.18.0 and I believe this is related. v0.17.3 works as expected.

@lovell ah thank you, I will try downgrading to v0.17.3 and check can confirm that it works as expected with v0.17.3

Commit 9e39a7f fixes the problem I've been investigating. Are you able to confirm the latest code on the master branch fixes things for you too?

...and commit f42a1ce fixes it properly, adding your test case too, thanks for reporting this.

These fixes are in v0.18.1 now available via npm. Please re-open if you're still having related problems.

Just checked with v0.18.1 and it works great!

Was this page helpful?
0 / 5 - 0 ratings