npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

image-pixels

v2.2.2

Published

Read pixel data from any image source

Downloads

17,120

Readme

image-pixels Build Status unstable

Get pixel data for a given URL, path, buffer, canvas, image or any other source. Intented for image based tests, first of all.

Usage

$ npm install image-pixels

var pixels = require('image-pixels')

// load single source
var {data, width, height} = await pixels('lena.png')

// load multiple sources in parallel
var [a, b, c] = await pixels.all([
	'./a.jpg',
	{ source: './b.png', cache: false },
	canvas
])

API

let {data, width, height} = await pixels(source, options?, cb?)

Loads pixel data from a source based on options. Possibly provide a callback for old-style async calls. Function returns a promise that gets resolved once the source is ready, so that is handy for await call.

In browser the result is ImageData object to easily output to context:

document.body.appendChild(document.createElement('canvas'))
	.getContext('2d')
	.putImageData(await pixels('lena.png'))

source

Type | Meaning ---|--- url, path | Relative/absolute path. data-uri, base64 | String with encoded or raw pixel data. Raw data requires options.shape. Encoded data may require options.type to skip mime type detection. HTMLImageElement, SVGImageElement, HTMLVideoElement, CSSImageValue | DOM/SVG image elements. Image, ImageData, ImageBitmap | Browser image data containers. File, Blob | Encoded image data. Canvas, Context2D | 2D drawing context, browser-only. WebGLContext | GL context, node/browser. Buffer, ArrayBuffer, Uint8Array, Uint8ClampedArray | Raw or encoded pixel data. Raw data requires options.shape. For encoded data options.typeskips mime type detection. Supported formats: png, bmp, gif, jpg. Float32Array, Float64Array, Array, Array of arrays | Float pixel data with values from 0..1 range. Promise | Promise expecting resolution to an image source. ndarray | Ndarray container with pixel data, compatible with get-pixels. options object | If source argument is omitted, it is taken from options.source, useful for pixels.all.

options

Option | Meaning ---|--- source | Source data, one from the list above. Applicable for multiple sources. shape or width/height | Input raw data shape [width, height]. type/mime | Mime type, optional for raw data to skip detection. clip | Clipping rectangle, [left, top, right, bottom] or {x?, y?, width?, height?}. cache | Cache loaded data for the source/url for faster subsequent fetch.

let list|dict = await pixels.all(list|dict, options?)

Load multiple sources or dict of sources in parallel. options can provide common for every source options.

// load font atlas sprite dict
var atlas = require('font-atlas')({chars: 'abc', step: [10, 10], shape: [20, 20]})

var dict = await pixels({
	a: {clip: [0,0,10,10]},
	b: {clip: [10,0,10,10]},
	c: {clip: [0,10,10,10]}
}, {cache: true, source: atlas})

Related packages

  • image-save − save image/pixel data to a file, canvas or array.
  • image-equal − assert image with baseline.

Similar packages

  • get-pixels − get ndarray with pixel data, limited set of sources.
  • ndarray-from-image − get-pixels with dtype.
  • get-image-pixels − get pixel data for Canvas/Image/Video elements, browser-only.
  • get-image-data − get image data for Canvas/Image/Video elements, browser-only.
  • readimage − read pixels data into an array in sync fashion in node.

License

© 2018 Dmitry Yv. MIT License.