![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
save-html-as-image
Advanced tools
This can be used for a couple of things, it can save HTML (DOM) as an image (JPG,PNG) and it can convert SVG images to PNG. Converting SVG to PNG is useful for Safari Browser compatibility since it cannot render SVG images.
saveAsPng(NODE_ELEMENT, USER_OPTIONS, DOM_OPTIONS);
saveAsJpeg(NODE_ELEMENT, USER_OPTIONS, DOM_OPTIONS);
import { saveAsPng, saveAsJpeg } from 'save-html-as-image';
const node = document.getElementById('elementId');
//download the node as png. Image (2019-12-01).png
saveAsPng(node);
//download the node as png. Report (2019-12-01).png
saveAsPng(node, { filename: 'Report', printDate: true });
//download the node as jpeg. Album.jpeg
saveAsJpeg(node, { filename: 'Album', printDate: false });
//download the node as jpeg. Album50.jpeg (With 50% of quality)
saveAsJpeg(node,
{ filename: 'Album50', printDate: false },
{ quality: 0.5 }
);
//download the node as png and Add padding and center element
saveAsPng(
node,
{ filename: 'Report', printDate: true },
{
backgroundColor: 'rgba(101,198,185,0.5)',
style: {
padding: '4px',
display: 'flex',
justifyContent: 'center',
},
}
);
The options are:
Modify the DOM and IMAGE to download.
The options available are:
You can hide elements adding the class "hide-when-downloading".
Hide elements apply display: hidden
to the elements with this class;
<section>
<article>One..</article>
<article class="hide-when-downloading">Two...</article>
</section>
saveAsPng(node, { filename: 'News', printDate: true });
//Only the first article will be visible on the image
Note: The class "hide-when-downloading" must be on root element, That we want hide.
You can remove elements adding the class "remove-when-downloading".
Remove Elements apply display: none
to the elements. So the space into the element will remove.
It's tested on the lasted Chrome (Chrome 76), Firefox and Safari.
We resolve the Safari support with a litte hack and replace svg with image. It's tested with FontAwesomeIcons svgs.
We use a collection of packages to generate and donwnload images, all in one action. The packages are:
[1.7.1] - 2022-02-16
FAQs
Save the html as image like png or jpg
The npm package save-html-as-image receives a total of 437 weekly downloads. As such, save-html-as-image popularity was classified as not popular.
We found that save-html-as-image demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.