Croppie is a fast, easy to use image cropping plugin with tons of configuration options!
var c = new Croppie(document.getElementById('item'), {
viewport: {
width: px,
height: px,
type: 'square|circle' //default 'square'
},
boundary: {
width: px,
height: px
},
customClass: '',
enableZoom: true|false, //default true // previously showZoom
showZoomer: true|false, //default true
mouseWheelZoom: true|false, //default true
update: function (cropper) { }
});
// bind an image to croppie
c.bind({
src: 'path/to/image',
points: [x1, y1, x2, y2]
});
// set the zoom programatically. Restricted to the min/max values of the slider
c.setZoom(1.5);
// get crop points from croppie
var data = c.get();
// get result from croppie
// returns Promise
var result = c.result('html|canvas').then(function (img) {
//img is html positioning & sizing the image correctly if resultType is 'html'
//img is base64 url of cropped image if resultType is 'canvas'
});
Or you can use jquery
$('#item').croppie(opts);
$('#item').croppie(method, args);
The outer container of the cropper
A class of your choosing to add to the container to add custom styles to your croppie
Enable zooming functionality. If set to false - scrolling and pinching would not zoom.
Hide or Show the zoom slider
Enable or disable the ability to use the mouse wheel to zoom in and out on a croppie instance
The inner container of the coppie. The visible part of the image
Get the crop points, and the zoom of the image.
Bind an image the croppie. Returns a promise to be resolved when the image has been loaded and the croppie has been initialized.
Get the resulting crop of the image.
type: 'canvas'
returns a base64 encoded image string.type: 'html'
returns html with the positioned correctly and overflow hidden.size: 'viewport'
returns the cropped image sized the same as the viewport.size: 'original'
returns the cropped image at the image's original dimensions.Set the zoom of a Croppie instance. The value passed in is still restricted to the min/max set by Croppie.
Destroy a croppie instance and remove it from the DOM
when the croppie is dragged around or zoomed, update is fired.
var basic = $('#demo-basic').croppie({
viewport: {
width: 150,
height: 200
}
});
basic.croppie('bind', {
url: 'demo/cat.jpg',
points: [77,469,280,739]
});
//on button click
basic.croppie('result', 'html');
var vanilla = new Croppie(document.getElementById('vanilla-demo'), {
viewport: { width: 100, height: 100 },
boundary: { width: 300, height: 300 },
showZoomer: false
});
vanilla.bind('demo/demo-2.jpg');
//on button click
vanilla.result('canvas');
$uploadCrop = $('#upload-demo').croppie({
viewport: {
width: 200,
height: 200,
type: 'circle'
},
boundary: {
width: 300,
height: 300
}
});
Croppie is supported in the following browsers:
IE9 may be supported, but it isn't tested. If you're able to test it and let us know, please do so on Github.
Croppie was built by Foliotek for use in Foliotek Presentation.
Check out some of our other open source tools: AjaxQ | LTI Tester