1
1
mirror of https://github.com/neosubhamoy/neosubhamoy-portfolio.git synced 2025-12-20 01:09:35 +05:30

(feat): added page qr code download feature

This commit is contained in:
2023-11-29 22:24:25 +05:30
parent 1613b99389
commit a412b5624f
2 changed files with 26 additions and 1 deletions

View File

@@ -418,4 +418,29 @@ function copy_to_clipboard(textContent, copyContext) {
else {
window.alert("Sorry, webClipboardAPI is not supported by your browser");
}
}
// function to download image from any url
function download_image(imageURL, imageName, downloadType = "image") {
if(downloadType === "qr") {
imageName = imageName.split('/');
imageName = imageName[imageName.length - 1];
imageName = "qrcode_" + imageName + "_page.png";
}
fetch(imageURL)
.then(response => response.blob())
.then(blob => {
var anchor = document.createElement('a');
var blobUrl = window.URL.createObjectURL(blob);
anchor.href = blobUrl;
anchor.download = imageName;
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
window.URL.revokeObjectURL(blobUrl);
})
.catch(error => console.error('Error downloading image:', error));
}