Comments (2)
This library works on the backend so you can use normal node libraries to download the data from the url. A (working) example of this would be something like
request = require("request"); // https://github.com/request/request
png = new (require('pngjs').PNG)(); // https://www.npmjs.com/package/pngjs
jsQR = require("jsqr");
request({
uri: "https://www.moo.com/images/qr-code/kitten-qr.jpg",
encoding: null // Force null encoding to get data as a buffer
}, function(err, resp, body) { // Download the image
if(err) {
console.error(err);
process.exit(1);
}
png.parse(body, function(err, decodedPng) { // Parse the png
if(err) {
console.error(err);
process.exit(1);
}
// Use jsQR to decode it
console.log(jsQR.decodeQRFromImage(decodedPng.data, decodedPng.width, decodedPng.height))
});
});
When I run this locally it produces http://www.moo.com/images/qr-code/hidden-kittens.jpg
.
One thing to note is even though this image had the jpg
extension, it's actually a png. If you need to support arbitrary urls I'd use something like https://www.npmjs.com/package/image-type to detect the image type correctly.
I'm going to close this issue since the above solution works as far as I know, but if I misunderstood or if you have more questions feel free to re-open.
from jsqr.
example for latest pngjs and jsqr
const nodeFetch = require('node-fetch')
const pngjs = require('pngjs')
const jsqr = require("jsqr");
const getCodeFromQrCodeImageUrl = (url) => {
return nodeFetch(url).then(res => res.buffer()).then(buff => {
const image = pngjs.PNG.sync.read(buff)
const data = new Uint8Array(image.data)
return jsqr(data, image.width, image.height).data
})
}
from jsqr.
Related Issues (20)
- aways wrong content for each times HOT 1
- QR Code that cannot be parsed in browser JS HOT 1
- Hello, may I ask if the QR code with lighter color can not be recognized? (请问是不能识别颜色较浅的二维码吗?) HOT 3
- How pass blob imageData rather than Url HOT 4
- This QR code cannot be recognized HOT 1
- Big QRCode cannot be parsed HOT 2
- Can't read QR code on iOS16 HOT 4
- qr on oracle
- Would you consider exposing intermediate decoding data?
- Unable to read QR code
- Would it be possible to scan barcodes?
- Error: Malformed data passed to binarizer. HOT 2
- Unable to read this Qrcode HOT 1
- This JSQR library do not work reading barcode in image. I think it has algorith issue HOT 2
- What's going on here? Why is the frame misaligned? HOT 1
- EAN-13 Format
- I discovered a QR code that cannot be recognized.
- crop qrcode error
- Cannot read transparent pixels
- Why do some images have return values? Some pictures don't
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsqr.