Image resize with inside option not working?
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
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)
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
Hope this helped - please re-open with more details if not.
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 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