Image cropper utility that crops an image in any polygonal shape chosen and returns a base64 of the cropped area.
$ npm install idcrop
const IdCrop = require("idcrop");
const idcrop = new IdCrop({
displaySelector: "#display",
toolbarSelector: "#toolbar",
previewSelector: "#preview"
});
idcrop.init();
The only required key in the configuration object is the CSS selector for the display area, but we have a bunch of configuration options that will be listed below.
Some events are dispatched to the document
in some key actions done to the cropper. These events are:
created
Dispatched when the IdCrop is loaded or reset. detail The IdCrop configuration object.handleCreated
Dispatched when a new handle is created. detail The x and y position of the created handle.resized
Dispatched when a handle is moved. detail The new x and y position of the moved handle.crop
Dispatched when a crop action happens. detail The dataURI for the image created.Right now we only have one getter method for the IdCrop which is:
idcrop.getPoints
This method returns a list with all the points added to the image relative to the real image size.You can create a container for display (cropping area), toolbar (for now, only filename) and preview (cropped area preview). Only the display area is required though.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>IdCrop</title>
<link rel="stylesheet" type="text/css href="https://unpkg.com/idcrop@1.2.2/dist/css/main.min.css">
</head>
<body>
<div id="display"></div>
<div id="toolbar"></div>
<div id="preview"></div>
</body>
</html>
$ npm install & npm start
We use a combination of eslint and prettier for the formatting and linting of our JS code.
$ npm run lint
$ npm run fix
We have a small npm script that handles the bumping of the version and the publishing of the package for us.
$ npm --no-git-tag version <newversion>
Copyright © 2017, Idwall. Released under the MIT license.