1.0.1 • Published 1 year ago

image-pixels-modify v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

description

The util to get image pixels data , edit martix data, output image base64.

Install

pnpm add image-pixels-modify

API

import { modifyImage } from "image-pixels-modify";
import img from "./assets/test.jpeg";

const peelingImage = (data: Uint8ClampedArray) => {
  for (let i = 0; i < data.length; i += 4) {
    data[i + 2] = data[i];
  }
};

const base64Str = await modifyImage(url, peelingImage);

1678416466584

Common Filters

reverseFilter

import { modifyImage, reverseFilter } from "image-pixels-modify";
import img from "./assets/test.jpeg";

const base64Str = await modifyImage(url, reverseFilter);

1678416962967

achromaticFilter

import { modifyImage, achromaticFilte } from "image-pixels-modify";
import img from "./assets/test.jpeg";

const base64Str = await modifyImage(url, achromaticFilte);

1678417199948

comicFilter

import { modifyImage, comicFilte } from "image-pixels-modify";
import img from "./assets/test.jpeg";

const base64Str = await modifyImage(url, comicFilte);

Data API Utils

getImageSize

to get image width and height

import { getImageSize } from "image-pixels-modify";
import img from "./assets/test.jpeg";

const [width, height] = await getImageSize(img);

normalize

imageData like r, g, b, a, r, g, b, a, ...

0, 0, 0, 255,0, 0, 0, 255,0, 0, 0, 255,0, 0, 0, 255,...

turn to multidimensional matrix

[

[ [0, 0, 0, 255],  [0, 0, 0, 255], ... ] , // first line
[ [0, 0, 0, 255],  [0, 0, 0, 255], ... ],  // second line

...

]

import { normaliz, getImageDataAndCanvas } from "image-pixels-modify";
import img from "./assets/test.jpeg";
const [imageData, _canvasElement] = await getImageDataAndCanvas(img);
const matrixData = normaliz(imageData, _canvas.width, _canvas.height);

restoreData

flat matrix pixels data to one dimensional array

import {
  normaliz,
  restoreData,
  getImageDataAndCanvas,
} from "image-pixels-modify";
import img from "./assets/test.jpeg";
const [imageData, _canvasElement] = await getImageDataAndCanvas(img);
const matrixData = normaliz(imageData, _canvas.width, _canvas.height);

// todos
// handle pixels humannize

// over handle mutil matrix data, then turn into one dimension array
const recoverData = restoreData(matrixData);
1.0.1

1 year ago

1.0.0

1 year ago