sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Image resize with inside option not working?

Open Korte68 opened this issue 8 years ago • 5 comments

Hi,

I try to resize an image this way:

sharp('../images/avatar/'+req.file.filename) .rotate() .resize(320, 200, {fit: sharp.fit.inside, withoutEnlargement: true}) .toBuffer(function(err, buffer)

but got this error: TypeError: Cannot read property 'inside' of undefined

Any idea?

Thank you

Korte68 avatar Oct 24 '18 13:10 Korte68

Based on the source code, we have to use the .max() option…am I right?

sharp('../images/avatar/'+req.file.filename) .rotate() .resize(320, 200) .max() .toBuffer(function(err, buffer)

Korte68 avatar Oct 24 '18 15:10 Korte68

Hello, it depends which version you are using. The latest v0.21.0 deprecated max() for { fit: sharp.fit.inside }.

http://sharp.pixelplumbing.com/en/stable/changelog/#v0210-4th-october-2018

lovell avatar Oct 24 '18 18:10 lovell

Hope this helped - please re-open with more details if not.

lovell avatar Nov 26 '18 19:11 lovell

In my own case, resize(2000, 2000, {fit: sharp.fit.inside}) absolutely does not work. 2000-by-2000 images results no matter the size of the input image. Using [email protected].

jeffmcmahan avatar Jun 24 '19 15:06 jeffmcmahan

@jeffmcmahan Here are the relevant unit tests that might help you. Feel free to open a new issue with a standalone code sample and image(s) if this is still a problem.

https://github.com/lovell/sharp/blob/cfa4f7d45c0dc4c098bb6e4a665720ee373af830/test/unit/resize.js#L180-L232

lovell avatar Jun 24 '19 15:06 lovell