mirror of
https://github.com/neosubhamoy/neosubhamoy-portfolio.git
synced 2025-12-19 17:03:01 +05:30
(feat): added page qr code download feature
This commit is contained in:
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user