Home Identifier Source Repository
import Cropng from 'cropng/src/cropng.js'
public class | source

Cropng

You can directly use instance of this class. cropng

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

image: Buffer | String

our image

Private Members
private

Method Summary

Public Methods
public

crop(measurements: Object, callback: function(err: Object, image: Object))

crop

public

scan(x: Number, y: Number, h: Number, w: Number, iter: function(x: Number, y: Number, idx: Number))

scan scans a region of a bitmap and calls iter for each region

Private Methods
private

_bufferizeImage turn an image into a buffer

private

_getMimeFromBuffer find the MIME type of a buffer

private

_getMimeFromPath find the MIME type of a file

private

_pack(image: Object, callback: function(err: Object, image: Object))

_pack packs the image to return the buffer to it's original format

Public Constructors

public constructor(image: Object | String) source

Params:

NameTypeAttributeDescription
image Object | String

the image to crop

Public Members

public image: Buffer | String source

our image

Private Members

private _bitmap: Object source

Public Methods

public crop(measurements: Object, callback: function(err: Object, image: Object)) source

crop

Params:

NameTypeAttributeDescription
measurements Object

the x,y,height and width to crop

measurements.x Number

the x coordinate to start from

measurements.y Number

the y coordinate to start from

measurements.height Number

the height of the crop

measurements.width Number

the width of the crop

callback function(err: Object, image: Object)

public scan(x: Number, y: Number, h: Number, w: Number, iter: function(x: Number, y: Number, idx: Number)) source

scan scans a region of a bitmap and calls iter for each region

Params:

NameTypeAttributeDescription
x Number

the x coordinate to start from

y Number

the y coordinate to start from

h Number

the height of the scan region

w Number

the width of the scan region

iter function(x: Number, y: Number, idx: Number)

a function to call on each region.

Private Methods

private _bufferizeImage(): Object source

_bufferizeImage turn an image into a buffer

Return:

Object

bufferized image

private _getMimeFromBuffer(buffer: Object): String source

_getMimeFromBuffer find the MIME type of a buffer

Params:

NameTypeAttributeDescription
buffer Object

an image buffer

Return:

String

the MIME type => "image/png"

private _getMimeFromPath(filePath: String): String source

_getMimeFromPath find the MIME type of a file

Params:

NameTypeAttributeDescription
filePath String

the path to a file

Return:

String

the MIME type => "image/png"

private _pack(image: Object, callback: function(err: Object, image: Object)) source

_pack packs the image to return the buffer to it's original format

Params:

NameTypeAttributeDescription
image Object

the image to pack

image.height Number

the height

image.width Number

the width

image.data Object

the image buffer

callback function(err: Object, image: Object)