npm.io
2.1.1 • Published 2 years ago

canvas-tint-image

Licence
MIT
Version
2.1.1
Deps
1
Size
8 kB
Vulns
0
Weekly
0
Stars
10

canvas-tint-image

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

A one trick pony package to tint an image with a canvas 2D context.

paypal coinbase twitter

Installation

npm install canvas-tint-image

Usage

import canvasTintImage from "canvas-tint-image";
import getCanvasContext from "get-canvas-context";
import AsyncPreloader from "async-preloader";

const context = getCanvasContext("2d", {
  width: 100,
  height: 100,
});

(async () => {
  const image = await AsyncPreloader.loadImage({ src: "image.jpg" });
  context.drawImage(canvasTintImage(image, "#f00", 0.5), 0, 0);
})();

API

canvasTintImage(image, color, [opacity]) ⇒ HTMLCanvasElement

Tint an image with a canvas 2D context.

Kind: global function

Param Type Default Description
image CanvasImageSource The image to tint
color string | CanvasGradient | CanvasPattern A CSS value
[opacity] number 0.5 Opacity of the tint between 0 and 1

License

MIT. See license file.

Keywords