当前位置:网站首页>JS image path conversion Base64 format
JS image path conversion Base64 format
2022-07-01 04:17:00 【-Geng Rui-】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id = 'app'>
</div>
<script> let url = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F4k%2Fs%2F02%2F2109242312005c1-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1659174217&t=2fd6120db3cd74070561b7e1e112d0e7"; function getBase64(imgUrl) {
window.URL = window.URL || window.webkitURL; var xhr = new XMLHttpRequest(); xhr.open("get", imgUrl, true); // crucial xhr.responseType = "blob"; xhr.onload = function () {
if (this.status == 200) {
// Get one blob object var blob = this.response; // crucial let oFileReader = new FileReader(); oFileReader.onloadend = function (e) {
let base64 = e.target.result; console.log(base64) }; oFileReader.readAsDataURL(blob); //==== To display pictures on the page , You can delete ==== } } xhr.send(); } getBase64(url); </script>
</body>
</html>
The operation results are as follows 
In this way, we will successfully convert the path to base64 Format base64 The path of can be used directly by putting it directly into the image path
The color code is as follows
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id = 'app'>
</div>
<script> let url = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F4k%2Fs%2F02%2F2109242312005c1-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1659174217&t=2fd6120db3cd74070561b7e1e112d0e7"; function getBase64(imgUrl) {
window.URL = window.URL || window.webkitURL; var xhr = new XMLHttpRequest(); xhr.open("get", imgUrl, true); // crucial xhr.responseType = "blob"; xhr.onload = function () {
if (this.status == 200) {
// Get one blob object var blob = this.response; // crucial let oFileReader = new FileReader(); oFileReader.onloadend = function (e) {
let base64 = e.target.result; console.log(base64) document.getElementById('app').innerHTML = `<img src = ${
base64} />`; }; oFileReader.readAsDataURL(blob); //==== To display pictures on the page , You can delete ==== } } xhr.send(); } getBase64(url); </script>
</body>
</html>

It's also very simple The main base64 Easy back-end processing It also has advantages in running speed
边栏推荐
- Coinbase in a bear market: losses, layoffs, stock price plunges
- MallBook:后疫情时代下,酒店企业如何破局?
- [send email with error] 535 error:authentication failed
- What is uid? What is auth? What is a verifier?
- MySQL advanced -- you will have a new understanding of MySQL
- 做网站数据采集,怎么选择合适的服务器呢?
- Browser top loading (from Zhihu)
- [Master / slave] router election in DD message
- 采购数智化爆发在即,支出宝'3+2'体系助力企业打造核心竞争优势
- 网站服务器:好用的网站服务器怎么选这五方面要关注
猜你喜欢

NFT: start NFT royalty journey with eip-2981

Task04 mathematical statistics

Use of JMeter counters
![Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]](/img/aa/a255d225d71e6ba2b497f8d59f5f11.jpg)
Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]

Quickly filter data such as clock in time and date: Excel filter to find whether a certain time point is within a certain time period

In the innovation community, the "100 cities Tour" of the gold warehouse of the National People's Congress of 2022 was launched
[today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET

JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction

Embedded System Development Notes 79: why should I get the IP address of the local network card

Possible problems and solutions of using scroll view to implement slider view
随机推荐
Recommend the best product development process in the Internet industry!
Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
【历史上的今天】6 月 30 日:冯·诺依曼发表第一份草案;九十年代末的半导体大战;CBS 收购 CNET
LeetCode 1380. Lucky number in matrix
Libevent Library Learning
Network metering - application layer
基于Unet的环路滤波
Chen Yu (Aqua) - Safety - & gt; Cloud Security - & gt; Multicloud security
mysql 函数 变量 存储过程
Deep learning | rnn/lstm of naturallanguageprocessing
这可能是你进腾讯最后的机会了..
什么是权限?什么是角色?什么是用户?
LeetCode 1399. Count the maximum number of groups
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.2 多属性注册协议(Multiple Registration Protocol (MRP))
Jenkins自动清理构建历史
Common thread methods and daemon threads
【TA-霜狼_may-《百人计划》】1.2.1 向量基础
“目标检测“+“视觉理解“实现对输入图像的理解
[JPCs publication] the Third International Conference on control theory and application in 2022 (icocta 2022)
js 图片路径转换base64格式