简体   繁体   English

在 URL 下载图片

[英]Download image in a URL

I have a QR in a URL我在 URL 中有一个二维码

I want to click a button and download the image of the QR in the URL我想点击一个按钮并下载URL中的QR图像

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 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-大.png

is it possible using PHP or Javascript?是否可以使用 PHP 或 Javascript?

I havent figured it out.我还没弄明白。

You can use fetch to get the content as a blob, then create an <a> element with the download attribute.您可以使用fetch将内容作为 blob 获取,然后创建一个具有 download 属性的<a>元素。 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%C2%A2erImageSizeRatio=0.4%C2%A2erImageUrl=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);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM