Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
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.
npm install imagejs
var ImageJS = require("imagejs");
// Create an uninitialized bitmap 320x200
// Note: the bitmap may be filled with random data
var bitmap = new ImageJS.Bitmap({width: 320, height: 200});
// Create a bitmap filled with green
var greenBitmap = new ImageJS.Bitmap({width: 100, height: 100, color: {r: 255, g: 255, b: 255, a: 255});
// Copy a bitmap
var copy = new ImageJS.Bitmap(otherBitmap);
// Create a bitmap and attach to supplied data structure
var attachedBitmap = new ImageJS.Bitmap({
width: 100,
height: 100,
data: new Buffer(4 * 100 * 100)
});
// Create an empty (null) bitmap, ready for reading from file or stream
var nullBitmap = new ImageJS.Bitmap();
// Set a pixel
// where: 0 <= x < width, 0 <= y < height, 0 <= r,g,b,a < 256
bitmap.setPixel(x,y, r,g,b,a);
// Set a pixesl using a color object
var yellow = {r:255, g:255, b:0}; // alpha defaults to 255
bitmap.setPixel(x,y, yellow);
// fetch the color of a pixel
var color = bitmap.getPixel(x,y);
// to improve performance you can supply the color object
var color = {};
color = bitmap.getPixel(x,y, color);
// Create a new bitmap that is a negative of the original
var negative = bitmap.negative();
// blur with simple gaussian filter
var blurred = bitmap.blur();
// create a new bitmap from a portion of another
var cropped = bitmap.crop({top: 50, left: 30, width: 100, height: 100});
// resize to 64x64 icon sized bitmap using nearest neighbor algorithm & stretch to fit
var thumbnail = bitmap.resize({
width: 64, height: 64,
algorithm: "nearestNeighbor"
});
// resize to 100x150 bitmap using bilinear interpolation and cropping to fit, gravity center
var thumbnail = bitmap.resize({
width: 100, height: 150,
algorithm: "bilinearInterpolation",
fit: "crop",
gravity: {x:0.5, y:0.5} // center - note: this is the default
});
// resize to 300x200 bitmap using bicubic interpolation and padding to fit, pad color solid red
var thumbnail = bitmap.resize({
width: 300, height: 200,
algorithm: "bicubicInterpolation",
fit: "pad",
padColor: {r:255, g:0, b:0, a:255}
});
Supported Resize Algorithms
// read from a file
var bitmap = new Bitmap();
bitmap.readFile(filename)
.then(function() {
// bitmap is ready
});
// read JPG data from stream
var stream = createReadStream();
var bitmap = new Bitmap();
bitmap.read(stream, { type: ImageJS.ImageType.JPG })
.then(function() {
// bitmap is ready
});
// write to a jpg file, quality 75 (default is 90)
return bitmap.writeFile("image.jpg", { quality:75 })
.then(function() {
// bitmap has been saved
});
// write PNG Image to a stream
var stream = createWriteStream();
return bitmap.write(stream, {type: ImageJS.ImageType.PNG})
.then(function() {
// bitmap has been written and stream ended
});
Version | Changes |
---|---|
0.0.1 | Initial Version |
0.0.2 |
|
0.0.3 |
|
0.0.5 |
|
0.0.6 |
|
FAQs
Image Processor
We found that imagejs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.