All Projects → gustavochavarria → save-html-as-image

gustavochavarria / save-html-as-image

Licence: MIT license
Download the HTML (DOM) to Image (JPG, PNG)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to save-html-as-image

dom-to-image-more
Generates an image from a DOM node using HTML5 canvas
Stars: ✭ 231 (+788.46%)
Mutual labels:  jpg, png, dom
highcharts-export-clientside
Module for Highcharts to exports charts client-side
Stars: ✭ 49 (+88.46%)
Mutual labels:  jpg, png
QuickImageFX
Simplifying image manipulation using GDI, Graphics32, OpenCV or Vampyre Imaging libraries
Stars: ✭ 41 (+57.69%)
Mutual labels:  jpg, png
Quickshot
Capture images of any View, SurfaceView or Bitmap from your Android app in: .jpg .png or .nomedia with simple oneliner codes.
Stars: ✭ 663 (+2450%)
Mutual labels:  jpg, png
ok-file-formats
Decoders for PNG, JPEG, WAV, and a few other file formats
Stars: ✭ 72 (+176.92%)
Mutual labels:  jpg, png
imei
IMEI - ImageMagick Easy Install
Stars: ✭ 126 (+384.62%)
Mutual labels:  jpg, png
Imagemin
[Unmaintained] Minify images seamlessly
Stars: ✭ 4,948 (+18930.77%)
Mutual labels:  jpg, png
autosvg
Autosvg is tracing tool, which can convert image format like (jpg,png,gif) into vector
Stars: ✭ 35 (+34.62%)
Mutual labels:  jpg, png
Optimise Images
Batch image resizer, optimiser and profiler using ImageMagick convert, OptiPNG, JpegOptim and optional ZopfliPNG, Guetzli and MozJPEG.
Stars: ✭ 64 (+146.15%)
Mutual labels:  jpg, png
Imageviewer
HDR, PFM, DDS, KTX, EXR, PNG, JPG, BMP image viewer and manipulator
Stars: ✭ 71 (+173.08%)
Mutual labels:  jpg, png
Gimage
A PHP library for easy image handling. 🖼
Stars: ✭ 148 (+469.23%)
Mutual labels:  jpg, png
heic-convert
🤳 convert heic/heif images to jpeg and png
Stars: ✭ 104 (+300%)
Mutual labels:  jpg, png
image-optimizer
Image optimization using PHP
Stars: ✭ 28 (+7.69%)
Mutual labels:  jpg, png
HEIF-converter
Converter for High Efficiency Image Format(HEIF)
Stars: ✭ 24 (-7.69%)
Mutual labels:  jpg, png
tinypng-free
Use the upload api of tinypng's homeage to compress images
Stars: ✭ 29 (+11.54%)
Mutual labels:  jpg, png
Exifr
📷 The fastest and most versatile JS EXIF reading library.
Stars: ✭ 448 (+1623.08%)
Mutual labels:  jpg, png
wordpress-plugin
Speed up your WordPress website. Optimize your JPEG and PNG images automatically with TinyPNG.
Stars: ✭ 78 (+200%)
Mutual labels:  jpg, png
saveddit
Bulk Downloader for Reddit
Stars: ✭ 130 (+400%)
Mutual labels:  jpg, png
ee.Screen
Takes screenshots of web pages for the list of URLs. Various resolutions, multiple formats (JPG, PDF, PNG and TXT)
Stars: ✭ 19 (-26.92%)
Mutual labels:  jpg, png
Image Optimizer
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.
Stars: ✭ 785 (+2919.23%)
Mutual labels:  jpg, png

save-html-as-image

npm version

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.

Structure

saveAsPng(NODE_ELEMENT, USER_OPTIONS, DOM_OPTIONS);
saveAsJpeg(NODE_ELEMENT, USER_OPTIONS, DOM_OPTIONS);

Usage

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',
      },
    }
  );

USER Options

The options are:

  • filename : The name of the file when download.
  • printDate : The date of the download.
  • forceFixText : Prevent some error with text.

DOM Options (New)

Modify the DOM and IMAGE to download.

The options available are:

  • backgroundColor : A string value for the background color, any valid CSS color value.
  • width, height : Width and height in pixels to be applied to node before rendering. (Only work together)
  • style : An object whose properties to be copied to node's style before rendering. Check (https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Properties_Reference)
  • quality : A number between 0 and 1 indicating image quality (e.g. 0.92 => 92%) of the JPEG image. Defaults to 1.0
  • pixelRatio : The pixel ratio of the captured image. Default use the actual pixel ratio of the device. Defaults to 1

Hide Elements

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.

Remove Elements

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.

Browsers

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.

Dependency

We use a collection of packages to generate and donwnload images, all in one action. The packages are:

  • 'file-saver'
  • 'html-to-image'
  • 'save-svg-as-png'

How it work

  • This library use html-to-image library for convert the HTML (DOM) to Image (jpg and png).
  • We use file saver to download the image generated.
  • We use save-svg-as-png to convert the svgs to img elements, only on safary or browser with stricter secure on
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].