3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

TypeScriptで写真からQRを読む

Last updated at Posted at 2018-11-12

qrcode-readerを使用した。
写真から読む場合、jsqrより認識率が高い印象。

https://www.npmjs.com/package/qrcode-reader
https://github.com/edi9999/jsqrcode

install

npm install -d qrcode-reader
yarn add -D qrcode-reader

execute

hoge.ts

  // import 
  var QrCode = require('qrcode-reader');

  // urlからdecodeを行う
  async decodeQrReader(url:string){
    var promise = new Promise<string>((resolve, reject) =>{
      const qr = new QrCode.default();
      qr.callback = (error:any,result:any)=>{
        if(error) reject(error);
        else resolve(result.result)
      }
      qr.decode(url);
    });
    const decoded = await promise;
    return decoded;
  }
  
  const decoded = await decodeQrReader('http://hoge/hoge.jpeg');
  console.log(decoded);

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?