Sometime ago, I wrote a small module called node-html-to-image. It generates images from HTML in Node.js. For more information, here is an article that explains how to use it. This week, it has been featured in NodeWeekly π
This week, I also released version 1.2. Let's see what's new in node-html-to-image
.
β¨ Transparency support
This feature was asked by jordan314. It wasn't possible to have a transparent background for png
images. Here is an example to achieve it with the new transparent
option:
const nodeHtmlToImage = require('node-html-to-image')
nodeHtmlToImage({
output: './image.png',
type: 'png',
transparent: true,
html: '<html><body>Hello world!</body></html>'
})
.then(() => console.log('The image was created successfully!'))
π Improve documentation
Users frequently asked me two questions about node-html-to-image
usage:
- How to use locally stored images?
- How to set my image resolution?
I added two sections directly in the README that answer these questions (image resolution and dealing with images).
I hope it will help π
β»οΈ Simplify test setup
I use tesseract to test the module works fine. It was tricky to install the engine on your computer in order to run tests. I moved to tesseract.js which is a Javascript port of this OCR engine. Running yarn installation command is now enough to setup the project before running tests.
π» The CLI has been released too!
node-html-to-image
has its own CLI. I think it is a good way to quickly give a try to the module.
What's new in node-html-to-image-cli
v1.1:
Add an option to provide content
It is now possible to use handlebars
with the CLI too. Here is an example:
npx node-html-to-image-cli ./index.html ./image.png --content ./content.json
index.html:
<!DOCTYPE html>
<html>
<body>
<h1>Hello {{you}}</h1>
</body>
</html>
content.json:
{
"you": "world"
}
Thanks to Julien Tanguy π
Add an option to support transparency
I also added an option transparent
to enable support of transparency in the CLI too:
npx node-html-to-image-cli --type png --transparent ./index.html ./image.png
Feel free check out the GitHub repositories if you are interested:
Want to support ? Don't forget to leave a βοΈ
Feedback or ideas are appreciated π Please tweet me if you have questions @YvonnickFrin!