Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
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 268 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.