javascript - View base64 encoded PNG in browser console - Stack Overflow

I'm constantly working with base64 encoded PNGs and want to preview them.My current workflow is t

I'm constantly working with base64 encoded PNGs and want to preview them.

My current workflow is to console.log(base64PNG) to the console, and then copy the image into a website like /converter/decode/image/png where I can decode + preview the image.

Is there some way (for ex. a Chrome extension) where I can just preview these inside the console?

I'm constantly working with base64 encoded PNGs and want to preview them.

My current workflow is to console.log(base64PNG) to the console, and then copy the image into a website like https://base64.guru/converter/decode/image/png where I can decode + preview the image.

Is there some way (for ex. a Chrome extension) where I can just preview these inside the console?

Share Improve this question asked Jun 26, 2023 at 15:49 David FerrisDavid Ferris 2,3557 gold badges35 silver badges61 bronze badges 1
  • Does this answer your question? How to display Base64 images in HTML – evolutionxbox Commented Jun 26, 2023 at 16:22
Add a ment  | 

2 Answers 2

Reset to default 4

You can just create an Image object and put the base64 as its src, including the data:image... part like this:

var image = new Image();
image.src = 'data:image/png;base64,iVBORw0K...';
document.body.appendChild(image);

It's what they call "Data URIs" and here's the patibility table for inner peace.

You can display images in the console (chrome) see https://github./adriancooney/console.image

I had a quick look through the code and created a simple example (the css padding/height/width etc are not right, but it works)

console.log("%c Image", "background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACvSURBVEhL7ZTBDYQgEEW3G/qxGm9Uwc0O7MGEJrxagEXM4uxIUAf/wRCTzbzMYSAkD/8QP+Rd02JBO0wAMQHEBJDXBQuF/FfpZW8dyHe0XnoVIBgdjZP0saMwHHvWx0U2Ve4E59tNxTL1jkKhrIEEOZ9fFb6533ZmWVVBgj33M/w1MTlqB3ZuZ1CPWGbDB/KQVMCQD68ohc6Jb+FoL0oFCR5jAogJICaA/I2gXXn3BSpPGV5H5sKpAAAAAElFTkSuQmCC'); background-size: 32px 32px; line-height: 32px; font-size: 1px; padding: 32px;").

The following function should help, I couldn't work out how to stop it repeating the image, so I just added background-repeat: no-repeat.

function logimage(h, w, uri) {
    console.log("%c+",`font-size: 1px; padding: ${Math.floor(h/2)}px ${Math.floor(w/2)}px; line-height: ${h}px;background: url('${uri}'); background-size: ${h}px ${w}px; background-repeat: no-repeat; color: transparent;`)
}

Depending on the source of your base64 strings, it should be pretty simple to create a bookmarklet to automate this.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745621236a4636527.html

相关推荐

  • javascript - View base64 encoded PNG in browser console - Stack Overflow

    I'm constantly working with base64 encoded PNGs and want to preview them.My current workflow is t

    10小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信