canvas-api-lite
v1.0.0
Published
An implementation of the Canvas API for use in non-browser contexts like Node.js.
Downloads
4
Readme
canvas-api-lite
An implementation of the Canvas API for use in non-browser contexts like Node.js.
Unlike node-canvas, this implementation has no native dependencies. However, this library only implements a small subset of the Canvas API.
The intended use case is to port code that operated against ImageData / Canvas to platforms like Node.js.
Supported APIs
This module exports the following types with implemented features as noted.
CanvasRenderingContext2D
constructor(canvas)
canvas
getter propertysave
/restore
createImageData
settings
argument not supported.
getImageData
settings
argument not supported.
putImageData
drawImage
- Scaling of the drawn image is not supported. Consider using a separate library like
resize-image-data
to scale prior to calling.
- Scaling of the drawn image is not supported. Consider using a separate library like
fillStyle
- Limited color formats (see below)
clearRect
fillRect
HTMLCanvasElement
constructor(width?, height?)
- Non-standard. This is how you instantiate this type without
document.createElement
.
- Non-standard. This is how you instantiate this type without
width
propertyheight
propertygetContext
"2d"
parameter only
toDataURL
- Limited to creating
image/png
URLs.
- Limited to creating
- DOM properties
id
,outerHTML
,innerHTML
,tagName
have very basic implementations. - Element constants like
ELEMENT_NODE
are defined.
HTMLImageElement
- The
Image
type is provided to construct anHTMLImageElement
. src
property- Currently limited to accepting PNG Data URLs.
width
getter propertyheight
getter property- Same as
naturalWidth
/naturalHeight
.
- Same as
naturalWidth
getter propertynaturalHeight
getter propertycomplete
getter propertyaddEventListener
removeEventListener
load
,error
event types only.
- The
ImageData
constructor
settings
argument not supported.- Both
width
andheight
must be passed. (Does not inferheight
fromwidth
and data array size.)
data
getter propertywidth
getter propertyheight
getter propertycolorSpace
getter property- Always
srgb
.
- Always
Supported color formats
- Hex colors (
#RGB
,#RGBA
,#RRGGBB
,#RRGGBBAA
) - RGB colors (
rgb(255, 255, 255)
,rgba(255, 255, 255, 0.5)
) - The ~150 standard CSS named colors.