Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
canvas-renderer
Advanced tools
HTML5 inspired canvas that can be rendered to PNG with no native dependencies.
HTML5 inspired canvas implemented in Node.js for rendering PNG images.
Install the canvas-renderer NPM package.
npm install canvas-renderer
The following example renders two triangles to test.png.
const fs = require("fs");
const canvasRenderer = require("canvas-renderer");
var canvas = canvasRenderer.createCanvas(100, 100);
var ctx = canvas.getContext("2d");
ctx.fillStyle = "#ff0000";
ctx.beginPath();
ctx.moveTo(10, 10);
ctx.lineTo(90, 10);
ctx.lineTo(10, 90);
ctx.fill();
ctx.fillStyle = "#0000ff";
ctx.beginPath();
ctx.moveTo(90, 90);
ctx.lineTo(90, 50);
ctx.lineTo(50, 90);
ctx.fill();
var testpng = fs.createWriteStream("test.png");
testpng.write(canvas.toPng());
testpng.close();
To create an instance of Canvas
, use the createCanvas(width, height)
method that is exposed
by the module. Use the getContext()
method on the canvas to get a CanvasContext
object.
width
(integer)
The width of the canvas in pixels.
height
(integer)
The height of the canvas in pixels.
backColor
(color)
Specifies the background color. See fillStyle
below for allowed values.
Default is transparent.
toPng([keywords])
Renders the canvas as a PNG data stream and returns it as a Buffer
. keywords
is an optional dictionary defining the keywords to be written to the PNG stream.
See https://www.w3.org/TR/PNG/#11keywords.
getContext()
Gets a CanvasContext object for drawing on this canvas.
toDataURL([type], [encoderOptions])
Renders the canvas as a dataURI. Note that the two parameters are currently
ignored since the only supported type
is image/png
.
fillStyle
(color)
Specifies the fill color that is used when the fill()
method is called. Allowed values are:
0xRRGGBBAA
"transparent"
"#2c4"
(#RGB)"#2c4f"
(#RGBA)"#22cc44"
(#RRGGBB)"#22cc44ff"
(#RRGGBBAA)"rgb(255, 124, 22)"
"rgb(255, 124, 22, 0.5)"
"rgb(255, 124, 22, 50%)"
"rgba(255, 124, 22, 0.5)"
"rgba(255, 124, 22, 50%)"
"rgb(23%, 45%, 75%)"
"rgb(23%, 45%, 75%, 0.5)"
"rgb(23%, 45%, 75%, 50%)"
"rgba(23%, 45%, 75%, 0.5)"
"rgba(23%, 45%, 75%, 50%)"
"hsl(134, 50%, 50%)"
"hsl(134, 50%, 50%, 0.5)"
"hsl(134, 50%, 50%, 50%)"
"hsla(134, 50%, 50%, 0.5)"
"hsla(134, 50%, 50%, 50%)"
"hwb(134, 50%, 50%)"
"hwb(134, 50%, 50%, 0.5)"
"hwb(134, 50%, 50%, 50%)"
beginPath()
Removes all existing subpaths and begins a new path.
moveTo(x, y)
Begins a new subpath by moving the cursor to the specified position.
lineTo(x, y)
Inserts an edge between the last and specified position.
arc(x, y, radius, startAngle, endAngle, [anticlockwise])
Adds an arc to the current subpath. See MDN for details.
closePath()
Starts a new subpath that begins in the same point as the start and end point of the previous one.
clearRect(x, y, width, height)
Fills the specified rectangle with fully transparent black without affecting the current paths.
fill([windingRule])
Fills the defined paths. windingRule
defines the winding rule to be used for
determining which areas are covered by the current path. Valid values are "evenodd"
and
"nonzero"
. Default is "nonzero"
.
fillRect(x, y, width, height)
Fills the specified rectangle without affecting the current paths.
save()
Saves the current transformation and fill style to a stack. The state can be
restored using restore()
.
restore()
Restores the last state saved by save()
and removes the state from the
state stack.
resetTransform()
rotate(angle)
scale(x, y)
setTransform(a, b, c, d, e, f)
transform(a, b, c, d, e, f)
translate(x, y)
canvas-renderer is released under the MIT license.
FAQs
HTML5 inspired canvas that can be rendered to PNG with no native dependencies.
We found that canvas-renderer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.