Skip to content

crop qrcode error #244

@chengdonglin

Description

@chengdonglin

Hi, from the decode result, I want to crop the qroce from the image, next is my code:

Jimp.read(buffer)
  .then(function (blockimg) {
    var width = blockimg.bitmap.width,
      height = blockimg.bitmap.height,
      imgData = blockimg.bitmap.data;
    var code = jsqr(imgData, width, height);
    if (code) {
      console.log(code); 
      Jimp.read(buffer).then((image) => {
        const cropMeta = {
          x: code.location.topLeftCorner.x - 20,
          y: code.location.topLeftCorner.y - 20,
          width:
            code.location.topRightCorner.x - code.location.topLeftCorner.x + 10,
          height:
            code.location.bottomLeftCorner.y -
            code.location.topLeftCorner.y +
            10,
        };
        image.crop(cropMeta.x, cropMeta.y, cropMeta.width, cropMeta.height);
        image.writeAsync("./output4.jpg");
      }); 
    } else {
      console.log("decode error");
    }
  })
  .catch(function (err2) {
    if (err2) {
      console.log(err2);
      cb(null, null);
    }
  });

but I find there is not crop all the qrcode part, image like below:
image

also if I change 10 to 50, it seem ok, But I have no idea that is a support method? or have any other method to find out x, y, width, height?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions