1
1
mirror of https://github.com/neosubhamoy/neosubhamoy-portfolio.git synced 2025-12-19 23:59: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

@@ -108,7 +108,7 @@
<img id="pageqrcode" src="https://api.qrserver.com/v1/create-qr-code/?data=https://neosubhamoy.dev&color=38BDF8&bgcolor=0F172A" alt="qrcode"> <img id="pageqrcode" src="https://api.qrserver.com/v1/create-qr-code/?data=https://neosubhamoy.dev&color=38BDF8&bgcolor=0F172A" alt="qrcode">
</div> </div>
</div> </div>
<button class="w-full px-4 py-2 rounded-full border-[2px] border-accent_primary text-accent_primary my-2 hover:shadow-lg hover:rounded-lg hover:shadow-accent_primary_transparent transition transform duration-500"><i class="fa-solid fa-download"></i>&nbsp; Download QR</button> <button class="w-full px-4 py-2 rounded-full border-[2px] border-accent_primary text-accent_primary my-2 hover:shadow-lg hover:rounded-lg hover:shadow-accent_primary_transparent transition transform duration-500" title="Download the page qr code" onclick="download_image(document.getElementById('pageqrcode').src, document.location.href, 'qr')"><i class="fa-solid fa-download"></i>&nbsp; Download QR</button>
<p class="text-xs text-accent_three my-2">* For better experiance please turn on auto weblink opening feature on your scanner app</p> <p class="text-xs text-accent_three my-2">* For better experiance please turn on auto weblink opening feature on your scanner app</p>
</div> </div>
<div class="extrashareopt w-full h-full flex flex-col py-3 px-7 border-l-[1px] border-[rgba(255,_255,_255,_0.15)]"> <div class="extrashareopt w-full h-full flex flex-col py-3 px-7 border-l-[1px] border-[rgba(255,_255,_255,_0.15)]">

View File

@@ -419,3 +419,28 @@ function copy_to_clipboard(textContent, copyContext) {
window.alert("Sorry, webClipboardAPI is not supported by your browser"); 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));
}