JSPM

ctx-identity

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q35471F
  • License ISC

An example of a canvas transform which doesn't alter the canvas at all (it's the identity transform). Useful as boilerplate for making real canvas transforms which do modify the canvas.

Package Exports

  • ctx-identity

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ctx-identity) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ctx-identity

An example of a canvas transform which doesn't alter the canvas at all (it's the identity transform). Useful as boilerplate for making real canvas transforms which do alter the canvas.

Build Status js-standard-style npm version Coverage Status

Why?

To implement a form of middleware for image manipulation. The contract is simple. Every middlware is a function that accepts a canvas and calls a callback, providing it with an error or a canvas. This makes it easy to compose various image manipulations any way you want. See imaginate, which offers an API that does exactly this.

Usage

var transform = cIdentity()

  • returns (function) transform - A function that accepts a canvas and returns it as-is

Examples

javascript (browser)

const cIdentity = require('ctx-identity')

var canvas = document.getElementById('aCanvas')

cIdentity()(canvas, function (err, newCanvas) {
  var ctx = newCanvas.getContext('2d')
  ...
})

Node.js

const cIdentity = require('ctx-identity')

var Canvas = require('canvas')
var canvas = new Canvas()

cIdentity()(canvas, function (err, newCanvas) {
  var ctx = newCanvas.getContext('2d')
  ...
})