ImageJS
Read, manipulate and write Images
Due to a lack of pure JavaScript Image manipulation libraries available, I decided to implement one.
This is an early release supporting only jpeg and png files and only the simplest resize algorithms
but there will be more to come.
Installation
npm install imagejs
New Features!
Contents
Interface
var ImageJS = require("imagejs");
Creating Bitmaps
var blankBitmap = new ImageJS.Bitmap({width: 320, height: 200});
var copy = new ImageJS.Bitmap(otherBitmap);
var attachedBitmap = new ImageJS.Bitmap({
width: 100,
height: 100,
data: new Buffer(4 * 100 * 100)
});
var nullBitmap = new ImageJS.Bitmap();
Manipulating Bitmaps
Set Pixel
bitmap.setPixel(x,y, a,r,g,b);
Negative
var negative = bitmap.negative();
Blur
var blurred = bitmap.blur();
Crop
var cropped = bitmap.crop({top: 50, left: 30, width: 100, height: 100});
Resize
var thumbnail = bitmap.resize({
width: 64, height: 64,
algorithm: "nearestNeighbor"
});
var thumbnail = bitmap.resize({
width: 100, height: 150,
algorithm: "bilinearInterpolation",
fit: "crop",
gravity: {x:0.5, y:0.5}
});
var thumbnail = bitmap.resize({
width: 300, height: 200,
algorithm: "bicubicInterpolation",
fit: "pad",
padColor: {r:255, g:0, b:0, a:255}
});
Supported Resize Algorithms
- nearestNeighbor
- bilinearInterpolation
- bicubicInterpolation
- bezierInterpolation
Reading Images
var bitmap = new Bitmap();
bitmap.readFile(filename)
.then(function() {
});
var stream = createReadStream();
var bitmap = new Bitmap();
bitmap.read(stream, { type: ImageJS.ImageType.JPG })
.then(function() {
});
Writing Images
return bitmap.writeFile("image.jpg", { quality:75 })
.then(function() {
});
var stream = createWriteStream();
return bitmap.write(stream, {type: ImageJS.ImageType.PNG})
.then(function() {
});
Release History
Version | Changes |
---|
0.0.1 | Initial Version |
0.0.2 | |
0.0.3 | |
0.0.4 | |