Skip to content

Commit 11fcf9a

Browse files
committed
feat: 修改了代码段
1 parent 4d150e9 commit 11fcf9a

4 files changed

Lines changed: 1158 additions & 50 deletions

File tree

codes/javascript/html/console.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function convertImageToBase64(image) {
2+
const canvas = document.createElement('canvas');
3+
const context = canvas.getContext('2d');
4+
canvas.width = image.width;
5+
canvas.height = image.height;
6+
context.drawImage(image, 0, 0);
7+
return canvas.toDataURL('image/png'); // 根据需要指定输出格式
8+
}
9+
10+
const showImageInConsole = src => {
11+
const img = new Image();
12+
img.setAttribute('src', src);
13+
document.body.appendChild(img);
14+
img.onload = () => {
15+
const base64 = convertImageToBase64(img);
16+
const css = [
17+
"padding: " + (img.height / 2 - 8) + "px " + img.width / 2 + "px;",
18+
"line-height: " + img.height + "px;",
19+
"background: url(" + base64 + ")no-repeat center / cover;",
20+
];
21+
console.log("%c ", css.join(""));
22+
consoleUtil(base64);
23+
document.body.removeChild(img);
24+
}
25+
}

0 commit comments

Comments
 (0)