Sharp: WebP shrink-on-load rounding error produces "extract_area: bad extract area"

Created on 14 Jul 2016  路  8Comments  路  Source: lovell/sharp

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

bug

Most helpful comment

v0.16.0 is now available via npm.

All 8 comments

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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paulieo10 picture paulieo10  路  3Comments

zilions picture zilions  路  3Comments

OleVik picture OleVik  路  3Comments

natural-law picture natural-law  路  3Comments

henbenla picture henbenla  路  3Comments