Convert html / svg to png / jpeg
npm install
npm start
http://localhost:3000/html-to-png
or http://localhost:3000/html-to-jpeg
, I would recommend writing a little test app with axiosconst file = ‘my-chart’;
const type = ‘jpeg’;
axios.post(http://localhost:3000/html-to-${type}
, {
// Note that the content that you send should have height/width attributes set on the first element since those are used for screenshot dimensions
content: fs.readFileSync(./${file}.svg
, { encoding: ‘utf8’ }).replace(/(\r\n|\n|\r)/gm, “ “)
})
.then((res) => {
console.log(res.data.msg);
if (res.data.msg == ‘Success’) {
let data = res.data.file.data;
fs.writeFileSync(./${file}.${type}
, Buffer.from(data));
}
})
.catch((error) => {
console.error(error);
});
```
Note: When you install it downloads a recent version of Chromium that is guaranteed to work with the library.
Requires Node v7.6.0 or greater.
This project is licensed under the The Unlicense https://github.com/Malexion/Html-to-Image-Webserver/blob/master/LICENSE.