Reputation: 1165
Is it possible to display a base64 image in html from a textfile containing the information?
The only way I know is to paste the whole content in html.
for instance:
<div>
<p>Taken from wikpedia</p>
<img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />
Maybe I have to use JS?
Upvotes: 0
Views: 2729
Reputation: 873
'use strict';
const fs = require('fs');
let buff = fs.readFileSync('test-image.png');
let base64data = buff.toString('base64');
console.log('Image converted to base 64 is:\n\n' + base64data);
Have you ever use NodeJs? If you don't know you have to install it. (https://nodejs.org/it/) You can put where you want the output string also inside the attribute src of the tag img.
Upvotes: 2