A JavaScript image cutter for the browser.
Allows for cutting images in pieces using <canvas>
Simply include the library and import it.
import ImageCutter from './ImageCutter';
const imageCutter = new ImageCutter('http://example.com/image.png');
await imageCutter.init();
// Cut a 200x200 rectangle on position 0, 0.
const image = imageCutter.cut(200, 200, 0, 0);
// Do something with the image.
...
Creates a new instance of ImageCutter
Example:
const imageCutter = new ImageCutter('http://example.com/image.png');
Setups the ImageCutter (downloads the image)
Example:
imageCutter.init().then(() => {
// Continue flow here.
});
// Or using async-await
await imageCutter.init();
Cuts the image in the given width, height and position.
NOTICE: x and y should be negative if you want to move the position of the image.
returns:String - The cutted image as a base64 string.
Example:
// Cuts an image 200x200 and 200 pixels from the top.
const image = imageCutter.cut(200, 200, 0, -200);
Cuts the whole image in pieces with the given width and height.
returns:Array
Example:
const images = imageCutter.cutAll(200, 200);