
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
get-canvas-pixel-color
Advanced tools
Micro module to get the color of a single pixel on a HTML canvas
Micro module to get the color of a single pixel on a HTML canvas
This is a convenience method around the canvas getImageData
API for just one pixel. If you need to get the color of a lot of pixels at once, it's best to use the underlying API: it's more efficient because you can specify the coordinates of the patch.
var canvas = document.querySelector('canvas');
var color = getCanvasPixelColor(canvas, 200, 10); // returns an array/object
//==> [255, 0, 100, 0.9]
//==> {r:255, g:0, b:100, a:0.9, rgb:'rgb(255,0,100)', rgba:'rgba(255,0,100,0.9)'}
var red = color.r; // 255
var red = color[0]; // 255
var alpha = color.a; // 0.9
var cssString = color.rgb; // 'rgb(255,0,100)'
npm install --save get-canvas-pixel-color
var getCanvasPixelColor = require('get-canvas-pixel-color');
import getCanvasPixelColor from 'get-canvas-pixel-color';
let canvas = document.querySelector('canvas');
let {r, g, b} = getCanvasPixelColor(canvas, 200, 10);
getCanvasPixelColor(canvas, x, y)
parameter | description |
---|---|
canvas | Type: canvas element or canvas context , required The canvas from which to take the color |
x | Type: number , required The x coordinate of the pixel to read |
y | Type: number , required The y coordinate of the pixel to read |
@returns | Type: array/object see usage example |
Here's an explanation of the files included in this repo
index.js
: source file, in ES6dist/get-canvas-pixel-color.js
: browser-ready file with AMD or a global variable called getCanvasPixelColor
dist/get-canvas-pixel-color.min.js
: same as above, minifiedNo dependencies.
MIT © Federico Brigante
FAQs
Micro module to get the color of a single pixel on a HTML canvas
The npm package get-canvas-pixel-color receives a total of 927 weekly downloads. As such, get-canvas-pixel-color popularity was classified as not popular.
We found that get-canvas-pixel-color 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
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.