Generate a image to base64. Fixed for Safari
npm install fixed-image-to-base64![]()
tag in HTML.
bash
npm i -S image-to-base64
`
Code Example:
`js
const imageToBase64 = require('image-to-base64');
//or
//import imageToBase64 from 'image-to-base64/browser';
imageToBase64("path/to/file.jpg") // Path to the image
.then(
(response) => {
console.log(response); // "cGF0aC90by9maWxlLmpwZw=="
}
)
.catch(
(error) => {
console.log(error); // Logs an error if there was one
}
)
`
Remember that you can also use an image URL as a parameter.
Code Example:
`js
imageToBase64("https://whatever-image/") // Image URL
.then(
(response) => {
console.log(response); // "iVBORw0KGgoAAAANSwCAIA..."
}
)
.catch(
(error) => {
console.log(error); // Logs an error if there was one
}
)
`
#### Browser Usage
You can import image-to-base64 using the