Appears there is some sort of rounding error going on. As I validated the inputs and found that if I change the top position from 1 to 0, it works.
Code to reproduce (sharp 0.15.0):
var sharp = require('sharp');
var image = sharp('./test/files/bad-crop.jpg');
image
.toFormat('webp') // if i don't do this step, it won't fail
.toBuffer(function(err, outputBuffer, info) {
console.log('info:', info); // reports 1080x607
sharp(outputBuffer)
.ignoreAspectRatio()
.resize(233, 131)
.extract({ top: 1, left: 0, width: 233, height: 130 }) // notice, height 130 + top of 1 = height of 131 - VALID
.toFormat('jpeg')
.toFile('result.jpg')
;
});
Results in:
Unhandled rejection Error: extract_area: bad extract area
at Error (native)
It only happens with this image: https://img1.wsimg.com/isteam/stock/5518eebf9a5d704c916de1acd4fe355e2c14463b39e4852697e1ec62859b5f5a?download
Hi Aaron, v0.15.0 had a small rounding error fixed as part of #452. Are you able to test with v0.15.1?
Using v0.15.1 I get:
Unhandled rejection Error: enum 'VipsOperationBoolean' has no member 'null', should be one of: and, or, eor, lshift, rshift
enum 'VipsOperationBoolean' has no member 'null', should be one of: and, or, eor, lshift, rshift
extract_area: bad extract area
at Error (native)
This is not a warning or "noise" as indicated in https://github.com/lovell/sharp/issues/509 -- it is failing.
Thanks for confirming this fails with v0.15.1 also (PR #511 on master should have fixed the contents of the error message). I'll make time to investigate further over the next couple of days.
I've created https://github.com/jcupitt/libvips/pull/489 for this.
Commit a5bd68e recalculates scaling factors after any use of shrink-on-load, as discussed at https://github.com/jcupitt/libvips/pull/489
Seems this bug is impacting more images than I thought. Any idea when you think this patch would be made available? Thanks @lovell !
@asilvas This will be in v0.16.0, which will ship with libvips v8.3.3 (v8.3.2 fixes a buffer overflow but introduces a performance regression - see https://github.com/jcupitt/libvips/blob/master/ChangeLog#L36-L42).
v0.16.0 is now available via npm.
Most helpful comment
v0.16.0 is now available via npm.