
Security News
Potemkin Understanding in LLMs: New Study Reveals Flaws in AI Benchmarks
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
ndarray-pixels
Advanced tools
Convert ndarray ↔ image data, on Web and Node.js.
Designed to be used with other ndarray-based packages.
Platform | JPEG | PNG | Other |
---|---|---|---|
Node.js | ✅ | ✅ | Based on sharp support |
Web | ✅ | ✅ | Based on browser support |
npm install --save ndarray-pixels
import { getPixels, savePixels } from 'ndarray-pixels';
const bytesIn = await fetch('./input.png')
.then((res) => res.arrayBuffer())
.then((arrayBuffer) => new Uint8Array(arrayBuffer));
// read
const pixels = await getPixels(bytesIn, 'image/png'); // Uint8Array -> ndarray
// modify
const [width, height] = pixels.shape;
for (let x = 0; x < width; ++x) {
for (let y = 0; y < height; ++y) {
pixels.set(x, y, 0, 255); // R
pixels.set(x, y, 1, 0.0); // G
pixels.set(x, y, 2, 0.0); // B
pixels.set(x, y, 3, 255); // A
}
}
// write
const bytesOut = await savePixels(pixels, 'image/png'); // ndarray -> Uint8Array
const fs = require('fs');
const { getPixels, savePixels } = require('ndarray-pixels');
const bufferIn = fs.readFileSync('./input.png');
// read
const pixels = await getPixels(bufferIn, 'image/png'); // Uint8Array -> ndarray
// modify
const [width, height] = pixels.shape;
for (let x = 0; x < width; ++x) {
for (let y = 0; y < height; ++y) {
pixels.set(x, y, 0, 255); // R
pixels.set(x, y, 1, 0.0); // G
pixels.set(x, y, 2, 0.0); // B
pixels.set(x, y, 3, 255); // A
}
}
// write
const bufferOut = await savePixels(pixels, 'image/png'); // ndarray -> Uint8Array
fs.writeFileSync('./output.png', bufferOut);
getPixels(
data
,mimeType
):Promise
<NdArray
<Uint8Array
<ArrayBufferLike
>>>
Defined in: index.ts:17
Decodes image data to an ndarray
.
MIME type is optional when given a path or URL, and required when given a Uint8Array.
Accepts image/png
or image/jpeg
in Node.js, and additional formats on browsers with
the necessary support in Canvas 2D.
Uint8Array
string
image/jpeg
, image/png
, etc.
Promise
<NdArray
<Uint8Array
<ArrayBufferLike
>>>
savePixels(
pixels
,typeOrOptions
):Promise
<Uint8Array
<ArrayBufferLike
>>
Defined in: index.ts:37
Encodes an ndarray
as image data in the given format.
If the source ndarray
was constructed manually with default stride, use
ndarray.transpose(1, 0)
to reshape it and ensure an identical result from getPixels(). For an
ndarray created by getPixels(), this isn't necessary.
Accepts image/png
or image/jpeg
in Node.js, and additional formats on browsers with
the necessary support in Canvas 2D.
NdArray
<Uint8Array
<ArrayBufferLike
> | Uint8ClampedArray
<ArrayBufferLike
>>
ndarray of shape W x H x 4.
object with encoding options or just the type
string
|
{ quality?
: number
; type?
: string
; }
object with encoding options or just the type
number
quality as a number from 0 to 1, inclusive
string
target format (image/jpeg
, image/png
, image/webp
, etc.)
Promise
<Uint8Array
<ArrayBufferLike
>>
FAQs
ndarray-pixels
The npm package ndarray-pixels receives a total of 86,290 weekly downloads. As such, ndarray-pixels popularity was classified as popular.
We found that ndarray-pixels demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.