当前位置:网站首页>JS -- image to base code, base to file object
JS -- image to base code, base to file object
2022-07-02 00:20:00 【A walking sheep】
【 Picture turn base code 】
function imgToBase(url){
let img = document.createElement("img")
img.src = url
img.setAttribute("crossOrigin",'Anonymous')
let canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
let ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
return canvas.toDataURL();
}
// call
imgToBase("https://img1.baidu.com/it/u=3382370226,1921570240&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=320")
【base Transcoding File object 】
//base-base code
//name- file name
function baseToFile(base, name) {
var arr = base.split(','),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n)
while (n--) {
u8arr[n] = bstr.charCodeAt(n)
}
return new File([u8arr], name, {
type: mime,
})
}
// call
baseToFile(base,"fileName.jpg")
边栏推荐
- Three methods of finding inverse numbers
- leetcode96不同的二叉搜索树
- Asp . Text of automatic reply to NETCORE wechat subscription number
- - Oui. Env. Fichier XXX, avec constante, mais non spécifié
- Leetcode medium question sharing (5)
- 挖财学堂开户打新债安全可靠嘛?
- Operate database transactions with jpatractionmanager
- Graduation season is both a farewell and a new beginning
- Take the enclave Park as a sample to see how Yuhua and Shaoshan play the song of Chang Zhu Tan integrated development
- Vue force cleaning browser cache
猜你喜欢
Talents come from afar, and Wangcheng district has consolidated the intellectual base of "strengthening the provincial capital"
Dongge cashes in and the boss retires?
比较通俗易懂的PID理解
ThreadLocal内存泄漏是什么,怎么解决
SQL Server Installation Guide
JS——图片转base码 、base转File对象
时间复杂度与空间复杂度
PWN attack and defense world cgpwn2
【QT】测试Qt是否能连接上数据库
Shell process control
随机推荐
Qt5.12.9 migration tutorial based on Quanzhi H3
Linux CentOS7安装Oracle11g的超完美新手教程
Pytorch learning record
E-commerce RPA robot helps brand e-commerce to achieve high traffic
The origin of usb-if Association and various interfaces
Openvino model performance evaluation tool DL workbench
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
时间复杂度与空间复杂度
GCC compilation
Asp . Text of automatic reply to NETCORE wechat subscription number
Resumption of attack and defense drill
js 公共库 cdn 推荐
[cascade classifier training parameters] training Haar cascades
From 20s to 500ms, I used these three methods
LeetCode 0241.为运算表达式设计优先级 - DFS
An intern's journey to cnosdb
Timer和ScheduledThreadPoolExecutor的区别
How to improve data quality
Is the securities account given by qiniu business school safe? Where can I open an account
LDR6035智能蓝牙音响可对手机设备持续充放电方案