控制台输出图片
实现代码
const toBase64 = (url) => {
return new Promise((resolve) => {
fetch(url)
.then(response => response.arrayBuffer())
.then(data => {
let base64 = btoa(
new Uint8Array(data).reduce((value, byte) => {
return value + String.fromCharCode(byte)
}, '')
)
base64 = 'data:image/png;base64,' + base64
resolve(base64)
})
})
}
(async function () {
const url = '/favicon.ico'
const base64 = await toBase64(url)
console.log('%c %c协同作业管理平台 %c zhenyutsai %c 版本:1.0.0',
` padding: 15px 15px;
background-image: url(${base64});
background-size: contain;
background-repeat: no-repeat;
color: transparent;`,
'color: #28388f; font-weight: 600; font-size:25px;',
'background: #35495e; padding: 4px; border-radius: 3px 0 0 3px; color: #fff',
'background: #41b883; padding: 4px; border-radius: 0 3px 3px 0; color: #fff'
)
})()
实现效果