ImageJS
A Pure JavaScript Image manipulation library.
Read and write JPG and PNG image files or streams and perform a number of operations on them.
Installation
npm install imagejs
New Features!
Backlog
- Graphics Object (draw and fill lines and shapes)
Contents
Interface
var ImageJS = require("imagejs");
Creating Bitmaps
var bitmap = new ImageJS.Bitmap({width: 320, height: 200});
var greenBitmap = new ImageJS.Bitmap({width: 100, height: 100, color: {r: 255, g: 255, b: 255, a: 255});
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, r,g,b,a);
var yellow = {r:255, g:255, b:0};
bitmap.setPixel(x,y, yellow);
Get Pixel
var color = bitmap.getPixel(x,y);
var color = {};
color = bitmap.getPixel(x,y, color);
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
- hermiteInterpolation
- bezierInterpolation
Rotate
var red = {r: 255, g: 0, b: 0, a: 255};
var rotated = bitmap.rotate({radians: 0.5, fit: "same", padColor: red});
var transparentWhite = {r: 255, g: 255, b: 255, a: 0};
var rotated = bitmap.rotate({degrees: -10, fit: "pad", padColor: transparentWhite});
var rotated = bitmap.rotate({degrees: 45, fit: "crop"});
var rotated = bitmap.rotate({degrees: 30, fit: "custom", width: 100, height: 150});
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.5 | |
0.0.6 | - Internal Restructuring
- Corrected Documentation
- Better Bitmap Construction
- Performance Improvements
|
0.0.8 | - Bug Fixes
- readFile this bug
- resize same aspect ratio fix
|
0.0.9 | |