
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
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 529 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.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.