Package detail

canvas-screenshot

dmnsgn1.1kMIT4.2.2

A one trick pony package to download an image from a canvas.

canvas, image, download, downloader

readme

canvas-screenshot

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

A one trick pony package to download an image from a canvas.

paypal coinbase twitter

Installation

npm install canvas-screenshot

Usage

import canvasScreenshot from "canvas-screenshot";
import canvasContext from "canvas-context";

// Create
const { context, canvas } = canvasContext("2d", {
  width: 100,
  height: 100,
});

// Draw
context.fillStyle = "salmon";
context.fillRect(40, 40, 20, 20);

// Export
const button = document.createElement("button");
button.addEventListener("click", () => {
  canvasScreenshot(canvas);
});

API

Modules

canvasScreenshot

Typedefs

CanvasScreenshotOptions : object

Options for canvas screenshot. All optional.

canvasScreenshot

canvasScreenshot(canvas, [options]) ⇒ string | Promise.<Blob>

Take a screenshot. Setting options.useBlob to true will consequently make the module async and return the latter.

Kind: Exported function Returns: string | Promise.<Blob> - A DOMString or a Promise resolving with a Blob.

Type is inferred from the filename extension:

  • png for "image/png" (default)
  • jpg/jpeg for "image/jpeg"
  • webp for "image/webp"
Param Type Default Description
canvas HTMLCanvasElement The canvas element
[options] CanvasScreenshotOptions {}

CanvasScreenshotOptions : object

Options for canvas screenshot. All optional.

Kind: global typedef Properties

Name Type Default Description
[filename] string "Screen Shot YYYY-MM-DD at HH.MM.SS.png" File name.
[quality] number 1 Quality between 0 and 1.
[useBlob] boolean Use canvas.toBlob.
[download] boolean true Automatically download the screenshot.

License

MIT. See license file.

changelog

Changelog

All notable changes to this project will be documented in this file. See commit-and-tag-version for commit guidelines.

4.2.2 (2024-07-06)

4.2.1 (2024-06-14)

Bug Fixes

  • don't reuse the DOM link for simultaneous download to work (1b07235), closes #10
  • handle extension less filename in getType (e9d11b7)
  • use type in toDataURL (d82fde3)

4.2.0 (2024-01-22)

Features

  • add support for image/webp (b645d38)

4.1.0 (2021-10-02)

Features

  • add exports field to package.json (4f2ab3e)

4.0.1 (2021-04-16)

4.0.0 (2021-04-16)

Code Refactoring

BREAKING CHANGES

  • switch to type module