image-sync

0.0.153 • Public • Published

image-sync

synchronously read, modify, and save PNG and JPG image data

Installation

npm i image-sync

Usage

var imageSync = require('image-sync');
var blur = require('image-blur-gaussian');

//read the image data
var img = imageSync.read('./cat.png'); //{width, height, data, saveAs}

//img.data has format [r,g,b,a, r,g,b,a ... ]

//blur the image
var rad = 16;
img.data = blur.blurImage(img.data,img.height,img.width,rad); 

//save the result as jpg...
img.saveAs(`./output.jpg`, 80); //save with 80% quality [default is 95%]

//or, save the result as png...
img.saveAs(`./output.png`);

//create blank image...
//blank(width,height,colorRGB=[255,255,255])
var blankImg = imageSync.blank(512,512);
blankImg.saveAs("./blank.png");

//create image with existing data buffer [colorRGB is ignored if rawData is set]
// blank(width,height,colorRGB=ignored,rawData=existingDataRGBA)

//grab pixel value [r,g,b,a] at integer coordinates
//var [r,g,b,a] = img.getPixel(x,y);

//grab pixel value [r,g,b,a] at float coordinates with interpolation
//var [r,g,b,a] = img.getPixelBilinear(x,y);

original cat.png

blurred 16 pixels output.png

See Also

stonks

Package Sidebar

Install

npm i image-sync

Weekly Downloads

3

Version

0.0.153

License

MIT

Unpacked Size

141 kB

Total Files

7

Last publish

Collaborators

  • stonkpunk