image-parser
An image parser that works.
This library uses lwip
to parse the images falling back to GraphicsMagick. π¨
βοΈ Installation
$ npm i --save image-parser
π Example
const ImageParser = require("image-parser");
let img = new ImageParser("https://octodex.github.com/images/privateinvestocat.jpg");
img.parse(err => {
if (err) { return console.error(err); }
console.log(img.getPixel(3, 3));
// PixelClass { r: 34, g: 30, b: 31, a: 1 }
});
π Documentation
ImageParser(source, options)
Creates a new instance of ImageParser
.
Params
- String|Buffer
source
: The image path/url or the aBuffer
object. - Object
options
: The options object to pass to thelwipify
.
Return
- ImageParser The
ImageParser
instance.
parse(cb)
Prepare the in-memory data (image pixels, buffers, size etc).
Params
- Function
cb
: The callback function.
width()
Returns the image width.
Return
- Number The image width.
height()
Returns the image height.
Return
- Number The image height.
getPixel(x, y)
Gets the pixel at given coordinates.
Params
- Number
x
: Thex
coordinate. - Number
y
: They
coordinate.
Return
- Pixel The
Pixel
instance containing the pixel data.
pixels()
Gets the image pixels.
Return
- Array An array of
Pixel
objects containing the pixel information.
resize(width, height, cb)
Resizes the image.
Params
- Number
width
: The new image width. - Number
height
: The new image height. - Function
cb
: The callback function.
crop(width, height, x, y, cb)
Crops the image.
Params
- Number
width
: The crop width. - Number
height
: The crop height. - Number
x
: The X coordinate. - Number
y
: The Y coordinate. - Function
cb
: The callback function.
save(filePath, cb)
Saves the image to disk.
Params
- String
filePath
: The output file path. - Function
cb
: The callback function.
π How to contribute
Have an idea? Found a bug? See how to contribute.
π« Where is this library used?
If you are using this library in one of your projects, add it in this list. β¨
image-to-ascii
βA Node.JS module that converts images to ASCII art.