当前位置:网站首页>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")
边栏推荐
- Resumption of attack and defense drill
- LeetCode中等题题分享(5)
- Cmake engineering related
- Leetcode 96 différents arbres de recherche binaires
- Is it safe to choose mobile phone for stock trading account opening in Beijing?
- Multi table operation - one to one, one to many and many to many
- LDR6035智能蓝牙音响可充可放(5.9.12.15.20V)快充快放设备充电
- SQL Server 安装指南
- Talents come from afar, and Wangcheng district has consolidated the intellectual base of "strengthening the provincial capital"
- From 20s to 500ms, I used these three methods
猜你喜欢
实例讲解将Graph Explorer搬上JupyterLab
Graduation season is both a farewell and a new beginning
Window sorting functions rank and deny for SQL data analysis_ rank、raw_ Number and lag, lead window offset function [usage sorting]
Dongge cashes in and the boss retires?
Database -- sqlserver details
Using multithreaded callable to query Oracle Database
USB-IF协会与各种接口的由来
Correlation - intra group correlation coefficient
Ldr6035 smart Bluetooth audio can be charged and released (5.9.12.15.20v) fast charging and fast releasing device charging
LDR6035智能蓝牙音响可充可放(5.9.12.15.20V)快充快放设备充电
随机推荐
Window sorting functions rank and deny for SQL data analysis_ rank、raw_ Number and lag, lead window offset function [usage sorting]
[QT] solve the problem that QT MSVC 2017 cannot compile
【mysql 07】GPG key retrieval failed: “Couldn‘t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022“
【opencv】train&test HOG+SVM
leetcode96不同的二叉搜索樹
cookie、session、tooken
使用 ES 实现疫情地图或者外卖点餐功能(含代码及数据)
Dongge cashes in and the boss retires?
Intelligent operation and maintenance practice: banking business process and single transaction tracking
【模板】自适应辛普森积分
ThreadLocal内存泄漏是什么,怎么解决
记录一下大文件上传偶然成功偶然失败问题
An intern's journey to cnosdb
Practical calculation of the whole process of operational amplifier hysteresis comparator
多表操作-一对一,一对多与多对多
Using SqlCommand objects in code
Node——Egg 实现上传文件接口
.env.xxx 文件,加了常量,卻undefined
Which app is better and more secure for stock mobile account opening
export default 导出的对象,不能解构问题,和module.exports的区别