New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ndarray-pixels

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ndarray-pixels - npm Package Compare versions

Comparing version 0.1.6 to 1.0.0

4

dist/browser-get-pixels.d.ts

@@ -1,5 +0,5 @@

import ndarray from 'ndarray';
export declare type GetPixelsCallback = (err: string | Event | null, pixels?: ndarray) => void;
import type { NdArray } from 'ndarray';
export declare type GetPixelsCallback = (err: string | Event | null, pixels?: NdArray) => void;
export default getPixels;
declare function getPixels(path: string, callback: GetPixelsCallback): void;
declare function getPixels(path: string | Uint8Array, type: string, callback: GetPixelsCallback): void;

@@ -1,2 +0,2 @@

import ndarray from 'ndarray';
import type { NdArray } from 'ndarray';
export interface SavePixelsOptions {

@@ -6,5 +6,5 @@ quality?: number;

export default savePixels;
declare function savePixels(array: ndarray, type: 'canvas'): HTMLCanvasElement;
declare function savePixels(array: ndarray, type: 'png'): Readable;
declare function savePixels(array: ndarray, type: 'jpeg' | 'jpg', options?: SavePixelsOptions): Readable;
declare function savePixels(array: NdArray, type: 'canvas'): HTMLCanvasElement;
declare function savePixels(array: NdArray, type: 'png'): Readable;
declare function savePixels(array: NdArray, type: 'jpeg' | 'jpg', options?: SavePixelsOptions): Readable;
declare class Readable {

@@ -11,0 +11,0 @@ private _promise;

@@ -1,2 +0,2 @@

import ndarray from 'ndarray';
import type { NdArray } from 'ndarray';
/**

@@ -14,3 +14,3 @@ * Decodes image data to an `ndarray`.

*/
declare function getPixels(data: string | Uint8Array, mimeType?: string): Promise<ndarray>;
declare function getPixels(data: string | Uint8Array, mimeType?: string): Promise<NdArray>;
/**

@@ -30,3 +30,3 @@ * Encodes an `ndarray` as image data in the given format.

*/
declare function savePixels(pixels: ndarray, mimeType: string): Promise<Uint8Array>;
declare function savePixels(pixels: NdArray, mimeType: string): Promise<Uint8Array>;
export { getPixels, savePixels };

@@ -1,2 +0,2 @@

var e=require("ndarray"),r=require("ndarray-ops");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(e),a=t(r);function i(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function o(e,r){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return i(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}function s(e,r,t){void 0===t&&(t={});var n=document.createElement("canvas");n.width=e.shape[0],n.height=e.shape[1];var a=n.getContext("2d"),i=a.getImageData(0,0,n.width,n.height);try{f(e,i.data)}catch(e){return h.from(Promise.reject(e))}a.putImageData(i,0,0);var o=t.quality?t.quality/100:void 0;switch(r){case"canvas":return n;case"jpg":case"jpeg":return u(n,"image/jpeg",o);case"png":return u(n,"image/png");default:throw new Error("[ndarray-pixels] Unsupported file type: "+r)}}function u(e,r,t){var n=new Promise(function(n,a){e.toBlob(function(e){try{var r=function(){if(e)return Promise.resolve(e.arrayBuffer()).then(function(e){n(new Uint8Array(e))});a(new Error("[ndarray-pixels] Failed to canvas.toBlob()."))}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},r,t)});return h.from(n)}function f(e,r,t){if(void 0===t&&(t=-1),4===e.shape.length)return f(e.pick(t),r,0);if(3===e.shape.length)if(3===e.shape[2])a.default.assign(n.default(r,[e.shape[0],e.shape[1],3],[4,4*e.shape[0],1]),e),a.default.assigns(n.default(r,[e.shape[0]*e.shape[1]],[4],3),255);else if(4===e.shape[2])a.default.assign(n.default(r,[e.shape[0],e.shape[1],4],[4,4*e.shape[0],1]),e);else{if(1!==e.shape[2])throw new Error("[ndarray-pixels] Incompatible array shape.");a.default.assign(n.default(r,[e.shape[0],e.shape[1],3],[4,4*e.shape[0],1]),n.default(e.data,[e.shape[0],e.shape[1],3],[e.stride[0],e.stride[1],0],e.offset)),a.default.assigns(n.default(r,[e.shape[0]*e.shape[1]],[4],3),255)}else{if(2!==e.shape.length)throw new Error("[ndarray-pixels] Incompatible array shape.");a.default.assign(n.default(r,[e.shape[0],e.shape[1],3],[4,4*e.shape[0],1]),n.default(e.data,[e.shape[0],e.shape[1],3],[e.stride[0],e.stride[1],0],e.offset)),a.default.assigns(n.default(r,[e.shape[0]*e.shape[1]],[4],3),255)}return r}var h=function(){function e(e){this._promise=e}return e.prototype.on=function(e,r){return"data"===e?this._promise.then(r):"error"===e?this._promise.catch(r):"end"===e&&this._promise.finally(r),this},e.from=function(r){return new e(r)},e}();exports.getPixels=function(e,r){try{return e instanceof Uint8Array&&"undefined"!=typeof Buffer&&(e=Buffer.from(e)),Promise.resolve(new Promise(function(t,a){!function(e,r,t){if(t=t||r,e instanceof Uint8Array){if("string"!=typeof r)throw new Error("[ndarray-pixels] Type must be given for Uint8Array image data");var a=new Blob([e],{type:r});e=URL.createObjectURL(a)}var i=new Image;i.crossOrigin="anonymous",i.onload=function(){URL.revokeObjectURL(e);var r=document.createElement("canvas");r.width=i.width,r.height=i.height;var a=r.getContext("2d");a.drawImage(i,0,0);var o=a.getImageData(0,0,i.width,i.height);t(null,n.default(new Uint8Array(o.data),[i.width,i.height,4],[4,4*i.width,1],0))},i.onerror=function(r){URL.revokeObjectURL(e),t(r)},i.src=e}(e,r,function(e,r){r&&!e?t(r):a(e)})}))}catch(e){return Promise.reject(e)}},exports.savePixels=function(e,r){try{return Promise.resolve(new Promise(function(t,n){var a=[],i=r.replace("image/","");s(e,i).on("data",function(e){return a.push(e)}).on("end",function(){return t(function(e){for(var r,t=0,n=o(e);!(r=n()).done;)t+=r.value.byteLength;for(var a,i=new Uint8Array(t),s=0,u=o(e);!(a=u()).done;){var f=a.value;i.set(f,s),s+=f.byteLength}return i}(a))}).on("error",function(e){return n(e)})}))}catch(e){return Promise.reject(e)}};
var e=require("ndarray"),r=require("ndarray-ops");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(e),a=t(r);function i(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function o(e,r){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return i(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}function s(e,r,t){void 0===t&&(t={});var n=document.createElement("canvas");n.width=e.shape[0],n.height=e.shape[1];var a=n.getContext("2d"),i=a.getImageData(0,0,n.width,n.height);try{f(e,i.data)}catch(e){return h.from(Promise.reject(e))}a.putImageData(i,0,0);var o=t.quality?t.quality/100:void 0;switch(r){case"canvas":return n;case"jpg":case"jpeg":return u(n,"image/jpeg",o);case"png":return u(n,"image/png");default:throw new Error("[ndarray-pixels] Unsupported file type: "+r)}}function u(e,r,t){var n=new Promise(function(n,a){e.toBlob(function(e){try{var r=function(){if(e)return Promise.resolve(e.arrayBuffer()).then(function(e){n(new Uint8Array(e))});a(new Error("[ndarray-pixels] Failed to canvas.toBlob()."))}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},r,t)});return h.from(n)}function f(e,r,t){if(void 0===t&&(t=-1),4===e.shape.length)return f(e.pick(t),r,0);if(3===e.shape.length)if(3===e.shape[2])a.default.assign(n.default(r,[e.shape[0],e.shape[1],3],[4,4*e.shape[0],1]),e),a.default.assigns(n.default(r,[e.shape[0]*e.shape[1]],[4],3),255);else if(4===e.shape[2])a.default.assign(n.default(r,[e.shape[0],e.shape[1],4],[4,4*e.shape[0],1]),e);else{if(1!==e.shape[2])throw new Error("[ndarray-pixels] Incompatible array shape.");a.default.assign(n.default(r,[e.shape[0],e.shape[1],3],[4,4*e.shape[0],1]),n.default(e.data,[e.shape[0],e.shape[1],3],[e.stride[0],e.stride[1],0],e.offset)),a.default.assigns(n.default(r,[e.shape[0]*e.shape[1]],[4],3),255)}else{if(2!==e.shape.length)throw new Error("[ndarray-pixels] Incompatible array shape.");a.default.assign(n.default(r,[e.shape[0],e.shape[1],3],[4,4*e.shape[0],1]),n.default(e.data,[e.shape[0],e.shape[1],3],[e.stride[0],e.stride[1],0],e.offset)),a.default.assigns(n.default(r,[e.shape[0]*e.shape[1]],[4],3),255)}return r}var h=function(){function e(e){this._promise=void 0,this._promise=e}return e.prototype.on=function(e,r){return"data"===e?this._promise.then(r):"error"===e?this._promise.catch(r):"end"===e&&this._promise.finally(r),this},e.from=function(r){return new e(r)},e}();exports.getPixels=function(e,r){try{return e instanceof Uint8Array&&"undefined"!=typeof Buffer&&(e=Buffer.from(e)),Promise.resolve(new Promise(function(t,a){!function(e,r,t){if(t=t||r,e instanceof Uint8Array){if("string"!=typeof r)throw new Error("[ndarray-pixels] Type must be given for Uint8Array image data");var a=new Blob([e],{type:r});e=URL.createObjectURL(a)}var i=new Image;i.crossOrigin="anonymous",i.onload=function(){URL.revokeObjectURL(e);var r=document.createElement("canvas");r.width=i.width,r.height=i.height;var a=r.getContext("2d");a.drawImage(i,0,0);var o=a.getImageData(0,0,i.width,i.height);t(null,n.default(new Uint8Array(o.data),[i.width,i.height,4],[4,4*i.width,1],0))},i.onerror=function(r){URL.revokeObjectURL(e),t(r)},i.src=e}(e,r,function(e,r){r&&!e?t(r):a(e)})}))}catch(e){return Promise.reject(e)}},exports.savePixels=function(e,r){try{return Promise.resolve(new Promise(function(t,n){var a=[],i=r.replace("image/","");s(e,i).on("data",function(e){return a.push(e)}).on("end",function(){return t(function(e){for(var r,t=0,n=o(e);!(r=n()).done;)t+=r.value.byteLength;for(var a,i=new Uint8Array(t),s=0,u=o(e);!(a=u()).done;){var f=a.value;i.set(f,s),s+=f.byteLength}return i}(a))}).on("error",function(e){return n(e)})}))}catch(e){return Promise.reject(e)}};
//# sourceMappingURL=ndarray-pixels-browser.js.map

@@ -1,2 +0,2 @@

import e from"ndarray";import t from"ndarray-ops";function a(e,t,a={}){const o=document.createElement("canvas");o.width=e.shape[0],o.height=e.shape[1];const i=o.getContext("2d"),h=i.getImageData(0,0,o.width,o.height);try{n(e,h.data)}catch(e){return s.from(Promise.reject(e))}i.putImageData(h,0,0);const p=a.quality?a.quality/100:void 0;switch(t){case"canvas":return o;case"jpg":case"jpeg":return r(o,"image/jpeg",p);case"png":return r(o,"image/png");default:throw new Error("[ndarray-pixels] Unsupported file type: "+t)}}function r(e,t,a){const r=new Promise((r,n)=>{e.toBlob(async e=>{e?r(new Uint8Array(await e.arrayBuffer())):n(new Error("[ndarray-pixels] Failed to canvas.toBlob()."))},t,a)});return s.from(r)}function n(a,r,s=-1){if(4===a.shape.length)return n(a.pick(s),r,0);if(3===a.shape.length)if(3===a.shape[2])t.assign(e(r,[a.shape[0],a.shape[1],3],[4,4*a.shape[0],1]),a),t.assigns(e(r,[a.shape[0]*a.shape[1]],[4],3),255);else if(4===a.shape[2])t.assign(e(r,[a.shape[0],a.shape[1],4],[4,4*a.shape[0],1]),a);else{if(1!==a.shape[2])throw new Error("[ndarray-pixels] Incompatible array shape.");t.assign(e(r,[a.shape[0],a.shape[1],3],[4,4*a.shape[0],1]),e(a.data,[a.shape[0],a.shape[1],3],[a.stride[0],a.stride[1],0],a.offset)),t.assigns(e(r,[a.shape[0]*a.shape[1]],[4],3),255)}else{if(2!==a.shape.length)throw new Error("[ndarray-pixels] Incompatible array shape.");t.assign(e(r,[a.shape[0],a.shape[1],3],[4,4*a.shape[0],1]),e(a.data,[a.shape[0],a.shape[1],3],[a.stride[0],a.stride[1],0],a.offset)),t.assigns(e(r,[a.shape[0]*a.shape[1]],[4],3),255)}return r}class s{constructor(e){this._promise=e}on(e,t){return"data"===e?this._promise.then(t):"error"===e?this._promise.catch(t):"end"===e&&this._promise.finally(t),this}static from(e){return new s(e)}}async function o(t,a){return t instanceof Uint8Array&&"undefined"!=typeof Buffer&&(t=Buffer.from(t)),new Promise((r,n)=>{!function(t,a,r){if(r=r||a,t instanceof Uint8Array){if("string"!=typeof a)throw new Error("[ndarray-pixels] Type must be given for Uint8Array image data");const e=new Blob([t],{type:a});t=URL.createObjectURL(e)}const n=new Image;n.crossOrigin="anonymous",n.onload=function(){URL.revokeObjectURL(t);const a=document.createElement("canvas");a.width=n.width,a.height=n.height;const s=a.getContext("2d");s.drawImage(n,0,0);const o=s.getImageData(0,0,n.width,n.height);r(null,e(new Uint8Array(o.data),[n.width,n.height,4],[4,4*n.width,1],0))},n.onerror=e=>{URL.revokeObjectURL(t),r(e)},n.src=t}(t,a,(e,t)=>{t&&!e?r(t):n(e)})})}async function i(e,t){return new Promise((r,n)=>{const s=[],o=t.replace("image/","");a(e,o).on("data",e=>s.push(e)).on("end",()=>r(function(e){let t=0;for(const a of e)t+=a.byteLength;const a=new Uint8Array(t);let r=0;for(const t of e)a.set(t,r),r+=t.byteLength;return a}(s))).on("error",e=>n(e))})}export{o as getPixels,i as savePixels};
import e from"ndarray";import t from"ndarray-ops";function a(e,t,a={}){const i=document.createElement("canvas");i.width=e.shape[0],i.height=e.shape[1];const o=i.getContext("2d"),h=o.getImageData(0,0,i.width,i.height);try{n(e,h.data)}catch(e){return s.from(Promise.reject(e))}o.putImageData(h,0,0);const p=a.quality?a.quality/100:void 0;switch(t){case"canvas":return i;case"jpg":case"jpeg":return r(i,"image/jpeg",p);case"png":return r(i,"image/png");default:throw new Error("[ndarray-pixels] Unsupported file type: "+t)}}function r(e,t,a){const r=new Promise((r,n)=>{e.toBlob(async e=>{e?r(new Uint8Array(await e.arrayBuffer())):n(new Error("[ndarray-pixels] Failed to canvas.toBlob()."))},t,a)});return s.from(r)}function n(a,r,s=-1){if(4===a.shape.length)return n(a.pick(s),r,0);if(3===a.shape.length)if(3===a.shape[2])t.assign(e(r,[a.shape[0],a.shape[1],3],[4,4*a.shape[0],1]),a),t.assigns(e(r,[a.shape[0]*a.shape[1]],[4],3),255);else if(4===a.shape[2])t.assign(e(r,[a.shape[0],a.shape[1],4],[4,4*a.shape[0],1]),a);else{if(1!==a.shape[2])throw new Error("[ndarray-pixels] Incompatible array shape.");t.assign(e(r,[a.shape[0],a.shape[1],3],[4,4*a.shape[0],1]),e(a.data,[a.shape[0],a.shape[1],3],[a.stride[0],a.stride[1],0],a.offset)),t.assigns(e(r,[a.shape[0]*a.shape[1]],[4],3),255)}else{if(2!==a.shape.length)throw new Error("[ndarray-pixels] Incompatible array shape.");t.assign(e(r,[a.shape[0],a.shape[1],3],[4,4*a.shape[0],1]),e(a.data,[a.shape[0],a.shape[1],3],[a.stride[0],a.stride[1],0],a.offset)),t.assigns(e(r,[a.shape[0]*a.shape[1]],[4],3),255)}return r}class s{constructor(e){this._promise=void 0,this._promise=e}on(e,t){return"data"===e?this._promise.then(t):"error"===e?this._promise.catch(t):"end"===e&&this._promise.finally(t),this}static from(e){return new s(e)}}async function i(t,a){return t instanceof Uint8Array&&"undefined"!=typeof Buffer&&(t=Buffer.from(t)),new Promise((r,n)=>{!function(t,a,r){if(r=r||a,t instanceof Uint8Array){if("string"!=typeof a)throw new Error("[ndarray-pixels] Type must be given for Uint8Array image data");const e=new Blob([t],{type:a});t=URL.createObjectURL(e)}const n=new Image;n.crossOrigin="anonymous",n.onload=function(){URL.revokeObjectURL(t);const a=document.createElement("canvas");a.width=n.width,a.height=n.height;const s=a.getContext("2d");s.drawImage(n,0,0);const i=s.getImageData(0,0,n.width,n.height);r(null,e(new Uint8Array(i.data),[n.width,n.height,4],[4,4*n.width,1],0))},n.onerror=e=>{URL.revokeObjectURL(t),r(e)},n.src=t}(t,a,(e,t)=>{t&&!e?r(t):n(e)})})}async function o(e,t){return new Promise((r,n)=>{const s=[],i=t.replace("image/","");a(e,i).on("data",e=>s.push(e)).on("end",()=>r(function(e){let t=0;for(const a of e)t+=a.byteLength;const a=new Uint8Array(t);let r=0;for(const t of e)a.set(t,r),r+=t.byteLength;return a}(s))).on("error",e=>n(e))})}export{i as getPixels,o as savePixels};
//# sourceMappingURL=ndarray-pixels-browser.modern.js.map
{
"name": "ndarray-pixels",
"version": "0.1.6",
"version": "1.0.0",
"description": "ndarray-pixels",

@@ -27,28 +27,28 @@ "main": "./dist/ndarray-pixels.js",

"dependencies": {
"@types/ndarray": "^1.0.8",
"get-pixels": "^3.3.2",
"@types/ndarray": "^1.0.10",
"get-pixels": "^3.3.3",
"ndarray": "^1.0.19",
"ndarray-ops": "^1.2.2",
"save-pixels": "^2.3.4"
"save-pixels": "^2.3.6"
},
"devDependencies": {
"@types/get-pixels": "^3.3.0",
"@types/ndarray-ops": "^1.2.0",
"@types/node": "^14.14.41",
"@types/save-pixels": "^2.3.0",
"@types/tape": "^4.13.0",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"browserify": "^17.0.0",
"eslint": "^7.24.0",
"microbundle": "^0.13.0",
"regenerator-runtime": "^0.13.7",
"replace-between": "^0.0.8",
"source-map-support": "^0.5.19",
"tap-spec": "^5.0.0",
"tape": "^5.2.2",
"tape-run": "^9.0.0",
"typedoc": "^0.20.35",
"typedoc-plugin-markdown": "^3.6.1",
"typescript": "^4.2.4"
"@types/get-pixels": "3.3.1",
"@types/ndarray-ops": "1.2.1",
"@types/node": "16.9.2",
"@types/save-pixels": "2.3.2",
"@types/tape": "4.13.2",
"@typescript-eslint/eslint-plugin": "4.31.1",
"@typescript-eslint/parser": "4.31.1",
"browserify": "17.0.0",
"eslint": "7.32.0",
"microbundle": "0.13.3",
"regenerator-runtime": "0.13.9",
"replace-between": "0.0.8",
"source-map-support": "0.5.20",
"tap-spec": "5.0.0",
"tape": "5.3.1",
"tape-run": "9.0.0",
"typedoc": "0.22.3",
"typedoc-plugin-markdown": "3.11.0",
"typescript": "4.4.3"
},

@@ -55,0 +55,0 @@ "files": [

@@ -69,3 +69,3 @@ # ndarray-pixels

▸ **getPixels**(`data`: *string* \| Uint8Array, `mimeType?`: *string*): *Promise*<ndarray\>
▸ **getPixels**(`data`, `mimeType?`): `Promise`<`NdArray`\>

@@ -79,13 +79,17 @@ Decodes image data to an `ndarray`.

#### Parameters:
#### Parameters
Name | Type | Description |
:------ | :------ | :------ |
`data` | *string* \| Uint8Array | |
`mimeType?` | *string* | `image/jpeg`, `image/png`, etc. |
| Name | Type | Description |
| :------ | :------ | :------ |
| `data` | `string` \| `Uint8Array` | |
| `mimeType?` | `string` | `image/jpeg`, `image/png`, etc. |
**Returns:** *Promise*<ndarray\>
#### Returns
Defined in: [index.ts:17](https://github.com/donmccurdy/ndarray-pixels/blob/091b259/src/index.ts#L17)
`Promise`<`NdArray`\>
#### Defined in
[index.ts:17](https://github.com/donmccurdy/ndarray-pixels/blob/3676ddc/src/index.ts#L17)
___

@@ -95,3 +99,3 @@

▸ **savePixels**(`pixels`: ndarray, `mimeType`: *string*): *Promise*<Uint8Array\>
▸ **savePixels**(`pixels`, `mimeType`): `Promise`<`Uint8Array`\>

@@ -107,12 +111,16 @@ Encodes an `ndarray` as image data in the given format.

#### Parameters:
#### Parameters
Name | Type | Description |
:------ | :------ | :------ |
`pixels` | ndarray | ndarray of shape W x H x 4. |
`mimeType` | *string* | `image/jpeg`, `image/png`, etc. |
| Name | Type | Description |
| :------ | :------ | :------ |
| `pixels` | `NdArray`<`Data`<`number`\>\> | ndarray of shape W x H x 4. |
| `mimeType` | `string` | `image/jpeg`, `image/png`, etc. |
**Returns:** *Promise*<Uint8Array\>
#### Returns
Defined in: [index.ts:48](https://github.com/donmccurdy/ndarray-pixels/blob/091b259/src/index.ts#L48)
`Promise`<`Uint8Array`\>
#### Defined in
[index.ts:48](https://github.com/donmccurdy/ndarray-pixels/blob/3676ddc/src/index.ts#L48)
<!--- API END --->
import ndarray from 'ndarray';
import type { NdArray } from 'ndarray';
export type GetPixelsCallback = (err: string | Event | null, pixels?: ndarray) => void;
export type GetPixelsCallback = (err: string | Event | null, pixels?: NdArray) => void;

@@ -5,0 +6,0 @@ export default getPixels;

import ndarray from 'ndarray';
import type { NdArray } from 'ndarray';
import ops from 'ndarray-ops';

@@ -8,7 +9,7 @@

function savePixels(array: ndarray, type: 'canvas'): HTMLCanvasElement;
function savePixels(array: ndarray, type: 'png'): Readable;
function savePixels(array: ndarray, type: 'jpeg' | 'jpg', options?: SavePixelsOptions): Readable;
function savePixels(array: NdArray, type: 'canvas'): HTMLCanvasElement;
function savePixels(array: NdArray, type: 'png'): Readable;
function savePixels(array: NdArray, type: 'jpeg' | 'jpg', options?: SavePixelsOptions): Readable;
function savePixels(
array: ndarray, type: 'canvas' | 'png' | 'jpeg' | 'jpg',
array: NdArray, type: 'canvas' | 'png' | 'jpeg' | 'jpg',
options: SavePixelsOptions = {}

@@ -65,3 +66,3 @@ ): Readable | HTMLCanvasElement {

function handleData(
array: ndarray,
array: NdArray,
data: Uint8Array | Uint8ClampedArray,

@@ -68,0 +69,0 @@ frame = -1

import getPixelsInternal from 'get-pixels';
import ndarray from 'ndarray';
import type { NdArray } from 'ndarray';
import savePixelsInternal from 'save-pixels';

@@ -17,3 +17,3 @@

*/
async function getPixels (data: string | Uint8Array, mimeType?: string): Promise<ndarray> {
async function getPixels (data: string | Uint8Array, mimeType?: string): Promise<NdArray> {
// In Node.js, get-pixels needs a Buffer and won't accept Uint8Array.

@@ -25,3 +25,3 @@ if (data instanceof Uint8Array && typeof Buffer !== 'undefined') {

return new Promise((resolve, reject) => {
getPixelsInternal(data, mimeType!, (err: Error | null, pixels: ndarray) => {
getPixelsInternal(data, mimeType!, (err: Error | null, pixels: NdArray) => {
if (pixels && !err) {

@@ -50,3 +50,3 @@ resolve(pixels);

*/
async function savePixels (pixels: ndarray, mimeType: string): Promise<Uint8Array> {
async function savePixels (pixels: NdArray, mimeType: string): Promise<Uint8Array> {
return new Promise((resolve, reject) => {

@@ -53,0 +53,0 @@ const chunks: Uint8Array[] = [];

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc