Home > other >  Download image in a URL
Download image in a URL

Time:02-02

I have a QR in a URL

I want to click a button and download the image of the QR in the URL

URL: https://quickchart.io/qr?text=http://tapo.app&dark=000&light=fff&ecLevel=H&margin=1&size=500¢erImageSizeRatio=0.4¢erImageUrl=https://app.tapo.app/Logo-Big.png

is it possible using PHP or Javascript?

I havent figured it out.

CodePudding user response:

You can use fetch to get the content as a blob, then create an <a> element with the download attribute. Clicking on the anchor will download the image.

fetch('https://quickchart.io/qr?text=http://tapo.app&dark=000&light=fff&ecLevel=H&margin=1&size=500¢erImageSizeRatio=0.4¢erImageUrl=https://app.tapo.app/Logo-Big.png').then(res => res.blob()).then(blob => {
    let url = URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = 'Image.png';
    a.click();
    URL.revokeObjectURL(url);
});
  • Related