Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- // Read the image file into a buffer
- const imageBuffer = fs.readFileSync('image.png');
- // Convert the buffer to a base64 string
- const imageBase64 = imageBuffer.toString('base64');
- // Create the data URL for the image
- const dataURL = `data:image/png;base64,${imageBase64}`;
- // Set the src attribute of an image element to the data URL
- const imageElement = document.getElementById('my-image');
- imageElement.src = dataURL;
- // https://www.base64-image.de
Add Comment
Please, Sign In to add comment