@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
33 lines (32 loc) • 986 B
JavaScript
// SPDX-License-Identifier: Apache-2.0
import QRCodeStyling from 'qr-code-styling';
export async function generateQrCode(url) {
const qrcode = new QRCodeStyling({
width: 300,
height: 300,
type: 'svg',
data: url,
image: 'images/logo/logo_icon.svg',
dotsOptions: {
color: '#575757ff',
type: 'rounded',
roundSize: true
},
backgroundOptions: {
color: '#e9ebee'
},
imageOptions: {
crossOrigin: 'anonymous',
margin: 6,
imageSize: 0.4
}
});
const blob = (await qrcode.getRawData('svg'));
const base64 = await blobToBase64(blob);
return `data:${blob.type};base64,${base64}`;
}
async function blobToBase64(blob) {
const buffer = await blob.arrayBuffer();
const base64String = btoa(new Uint8Array(buffer).reduce((data, byte) => data + String.fromCodePoint(byte), ''));
return base64String;
}