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 files and only the simplest resize algorithm but there will be more to come.
Installation
npm install imagejs
New Features!
Coming Soon
- Bicubic Interpolation
- Crop
- Pad
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
bitmap.setPixel(x,y, a,r,g,b);
var negative = bitmap.negative();
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: 100, height: 150,
algorithm: "bilinearInterpolation",
fit: "pad",
padColor: {r:255, g:0, b:0, a:255}
});
Supported Resize Algorithms
- nearestNeighbor
- bilinearInterpolation
Reading Images
var bitmap = new Bitmap();
bitmap.readFile(filename)
.then(function() {
});
var stream = createReadStream();
var bitmap = new Bitmap();
bitmap.read(stream, ImageJS.ImageType.JPG)
.then(function() {
});
Writing Images
return bitmap.writeFile(filename)
.then(function() {
});
var stream = createWriteStream();
return bitmap.write(stream, ImageJS.ImageType.PNG)
.then(function() {
});
Release History
Version | Changes |
---|
0.0.1 | Initial Version |
0.0.2 | |