canvas-tint-image
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

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(tintImage(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.

Package Sidebar

Install

npm i canvas-tint-image

Weekly Downloads

67

Version

2.1.0

License

MIT

Unpacked Size

7.82 kB

Total Files

6

Last publish

Collaborators

  • dmnsgn