当前位置:网站首页>JS download pictures
JS download pictures
2022-06-26 06:33:00 【YogaMiller】
fucntion downloadIamge(imgsrc, name) {
let image = new Image();
// To solve the cross domain Canvas pollution problem
image.setAttribute("crossOrigin", "anonymous");
image.onload = function() {
let canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;
let context = canvas.getContext("2d");
context.drawImage(image, 0, 0, image.width, image.height);
let url = canvas.toDataURL("image/png"); // photographic base64 Encoding data
let a = document.createElement("a"); // Generate a a Elements
let event = new MouseEvent("click"); // Create a click event
a.download = name || "photo"; // Set picture name
a.href = url; // The generated URL Set to a.href attribute
a.dispatchEvent(event); // Trigger a Click event for
};
image.src = imgsrc;
}
// Poor compatibility ,QQ Browsers don't work , 64 No version of Google
function downloadImg(src, name){
let canvas = document.createElement('canvas'),
img = document.createElement('img');
img.src = src;
img.setAttribute("crossOrigin",'Anonymous')
img.onload = function(e) {
canvas.width = img.width;
canvas.height = img.height;
var context = canvas.getContext('2d');
context.drawImage(img, 0, 0, img.width, img.height);
canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height);
canvas.toBlob( (blob) => {
let link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = ' file name ';
link.click();
}, "image/jpg");
}
}
1. data: agreement base64?
2. blob: agreement ?
边栏推荐
- 营销技巧:相比较讲产品的优点,更有效的是要向客户展示使用效果
- The sysdig 2022 cloud native security and usage report found that more than 75% of the running containers have serious vulnerabilities
- typescript的type
- GoF23—工厂模式
- Thinking and summary of technical ability
- zip(*arg)的用法
- Thinking skills of technical leaders
- 【golang】time相关
- Transformer中的Self-Attention以及Multi-Head Self-Attention(MSA)
- Go语言学习笔记 1.2-变量篇
猜你喜欢

EFK昇級到ClickHouse的日志存儲實戰

Several promotion routines of data governance

Understanding of nil in go language

Prometheus和Zabbix的对比

Jasminum plug-in of Zotero document management tool

GoF23—原型模式

直播预告丨消防安全讲师培训“云课堂”即将开讲!

MySQL 索引底层原理

STM 32 使用cube 生成TIM触发ADC并通过DMA传输的问题

Message queue - function, performance, operation and maintenance comparison
随机推荐
Distribution operation of D
Design and practice of low code real-time data warehouse construction system
Transaction and message semantics
Web components series (10) -- realize the basic layout of mycard
Temperature alarm
How to design a good technical scheme
Introduction to canal deployment, principle and use
稀疏数组sparsearray
MVC source code sharing
Thinking and summary of technical ability
架构设计方法
Laravel implements groupby to query the number of packets
Go语言学习笔记 1.1
Introduction to the use of TS generics in functions, interfaces and classes
同步通信和异步通信的区别以及优缺点
Install pyinstaller
ts中枚举类型(enum)简单使用
Experience the new features of Milvus 2.0 together
Dpdk - tcp/udp protocol stack server implementation (I)
MySQL 数据库的小白安装与登录