4.2.0 • Published 4 months ago

canvas-screenshot v4.2.0

Weekly downloads
20
License
MIT
Repository
github
Last release
4 months ago

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

npm.io

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

Typedefs

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"
ParamTypeDefaultDescription
canvasHTMLCanvasElementThe canvas element
optionsCanvasScreenshotOptions{}

CanvasScreenshotOptions : object

Options for canvas screenshot. All optional.

Kind: global typedef Properties

NameTypeDefaultDescription
filenamestring"Screen Shot YYYY-MM-DD at HH.MM.SS.png"File name.
qualitynumber1Quality between 0 and 1.
useBlobbooleanUse canvas.toBlob.
downloadbooleantrueAutomatically download the screenshot.

License

MIT. See license file.

4.2.0

4 months ago

4.1.0

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.0.0

4 years ago

2.0.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

6 years ago