Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crop qrcode error #244

Open
chengdonglin opened this issue Sep 14, 2023 · 0 comments
Open

crop qrcode error #244

chengdonglin opened this issue Sep 14, 2023 · 0 comments

Comments

@chengdonglin
Copy link

chengdonglin commented Sep 14, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant