{"id":16125725,"url":"https://github.com/dy/image-pixels","last_synced_at":"2025-09-12T21:33:16.500Z","repository":{"id":57272095,"uuid":"154046125","full_name":"dy/image-pixels","owner":"dy","description":"Load pixel data from any image source","archived":false,"fork":false,"pushed_at":"2019-01-26T01:48:52.000Z","size":1151,"stargazers_count":31,"open_issues_count":8,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-28T06:41:49.708Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dy.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-21T19:48:02.000Z","updated_at":"2024-12-15T20:05:56.000Z","dependencies_parsed_at":"2022-09-11T13:20:45.544Z","dependency_job_id":null,"html_url":"https://github.com/dy/image-pixels","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fimage-pixels","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fimage-pixels/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fimage-pixels/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fimage-pixels/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dy","download_url":"https://codeload.github.com/dy/image-pixels/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232792150,"owners_count":18577262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T21:31:07.935Z","updated_at":"2025-01-06T21:54:58.656Z","avatar_url":"https://github.com/dy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# image-pixels [![Build Status](https://travis-ci.org/dy/image-pixels.svg?branch=master)](https://travis-ci.org/dy/image-pixels) [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges)\n\nGet pixel data for a given URL, path, buffer, canvas, image or any other source. Intented for image based tests, first of all.\n\n\n## Usage\n\n[![$ npm install image-pixels](http://nodei.co/npm/image-pixels.png?mini=true)](http://npmjs.org/package/image-pixels)\n\n```javascript\nvar pixels = require('image-pixels')\n\n// load single source\nvar {data, width, height} = await pixels('lena.png')\n\n// load multiple sources in parallel\nvar [a, b, c] = await pixels.all([\n\t'./a.jpg',\n\t{ source: './b.png', cache: false },\n\tcanvas\n])\n```\n\n## API\n\n### `let {data, width, height} = await pixels(source, options?, cb?)`\n\nLoads 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.\n\nIn browser the result is `ImageData` object to easily output to context:\n\n```js\ndocument.body.appendChild(document.createElement('canvas'))\n\t.getContext('2d')\n\t.putImageData(await pixels('lena.png'))\n```\n\n#### `source`\n\nType | Meaning\n---|---\n`url`, `path` | Relative/absolute path.\n`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.\n`HTMLImageElement`, `SVGImageElement`, `HTMLVideoElement`, `CSSImageValue` | DOM/SVG image elements.\n`Image`, `ImageData`, `ImageBitmap` | Browser image data containers.\n`File`, `Blob` | Encoded image data.\n`Canvas`, `Context2D` | 2D drawing context, browser-only.\n`WebGLContext` | GL context, node/browser.\n`Buffer`, `ArrayBuffer`, `Uint8Array`, `Uint8ClampedArray` | Raw or encoded pixel data. Raw data requires `options.shape`. For encoded data `options.type`skips mime type detection. Supported formats: `png`, `bmp`, `gif`, `jpg`.\n`Float32Array`, `Float64Array`, `Array`, `Array` of arrays | Float pixel data with values from `0..1` range.\n`Promise` | Promise expecting resolution to an image source.\n`ndarray` | [Ndarray](https://ghub.io/ndarray) container with pixel data, compatible with [get-pixels](https://ghub.io/get-pixels).\noptions object | If `source` argument is omitted, it is taken from `options.source`, useful for `pixels.all`.\n\n#### `options`\n\nOption | Meaning\n---|---\n`source` | Source data, one from the list above. Applicable for multiple sources.\n`shape` or `width`/`height` | Input raw data shape `[width, height]`.\n`type`/`mime` | Mime type, optional for raw data to skip detection.\n`clip` | Clipping rectangle, `[left, top, right, bottom]` or `{x?, y?, width?, height?}`.\n`cache` | Cache loaded data for the source/url for faster subsequent fetch.\n\n### `let list|dict = await pixels.all(list|dict, options?)`\n\nLoad multiple sources or dict of sources in parallel. `options` can provide common for every source options.\n\n```js\n// load font atlas sprite dict\nvar atlas = require('font-atlas')({chars: 'abc', step: [10, 10], shape: [20, 20]})\n\nvar dict = await pixels({\n\ta: {clip: [0,0,10,10]},\n\tb: {clip: [10,0,10,10]},\n\tc: {clip: [0,10,10,10]}\n}, {cache: true, source: atlas})\n```\n\n## Related packages\n\n* [image-save](https://ghub.io/image-save) − save image/pixel data to a file, canvas or array.\n* [image-equal](https://ghub.io/image-equal) − assert image with baseline.\n\n## Similar packages\n\n* [get-pixels](https://ghub.io/get-pixels) − get ndarray with pixel data, limited set of sources.\n* [ndarray-from-image](https://github.com/thibauts/ndarray-from-image) − get-pixels with dtype.\n* [get-image-pixels](https://ghub.io/get-image-pixels) − get pixel data for Canvas/Image/Video elements, browser-only.\n* [get-image-data](https://ghub.io/get-image-data) − get image data for Canvas/Image/Video elements, browser-only.\n* [readimage](https://ghub.io/readimage) − read pixels data into an array in sync fashion in node.\n\n## License\n\n© 2018 Dmitry Yv. MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdy%2Fimage-pixels","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdy%2Fimage-pixels","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdy%2Fimage-pixels/lists"}