Converting the QR code to image
-
Get QR Code:
Get the qr_code from the API response.
-
Basic Decode:
Decode the qr_code data (which is encoded using Base64 encoding).
Example: In JS,
const decodedQrCode = window.atob(qr_code);
-
Convert to QR Image URL:
Use any known internal method of your programming language or use an external library to convert decodedQrCode to QR image URL.
Example: qrcode npm package, sample code block as per the npm package readme doc,
For ES6/ES7
import QRCode from 'qrcode' let **qr_url =** null; // With promises QRCode.toDataURL(decodedQrCode) .then((url) => { console.log(url) **qr_url** = url; }) .catch((err) => { console.error(err) })
-
Render QR Image:
set the qr_url in the src attribute of image element in HTML.
Example:
<img :src="qr_url" // QR image url to render in UI. class="" // add relevant styles alt="QR image" />
Updated 7 months ago