Skip to content

.resize() crops image when crop is unnecessary #831

Description

@max-degterev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions