( open in modal window )
( display url after cropping )
( no background image )
( define the controls available )
( if the picture is already available )
Simplest implementation. Beware that you must provide width and height of the container.
var cropperHeader = new Croppic('yourId');
<div id="yourId"></div>
#yourId { width: 200px; height: 150px; position:relative; /* or fixed or absolute */ }
Path to your img upload proccessing file.
var cropperOptions = { uploadUrl:'path_to_your_image_proccessing_file.php' } var cropperHeader = new Croppic('yourId', cropperOptions);
You will be receiving the image file via AJAX POST method as multipart/form-data;
(note that ajax is limited to same domain requests)
After successful image saving, you must return the following json.
( image width and height required for limiting max zoom, so images dont come out blurry. )
{ "status":"success", "url":"path/img.jpg", "width":originalImgWidth, "height":originalImgHeight }
In case of error response
{ "status":"error", "message":"your error message text" }
Additional data you want to send to your image upload proccessing file
var cropperOptions = { uploadUrl:'path_to_your_image_proccessing_file.php', uploadData:{ "dummyData":1, "dummyData2":"text" } } var cropperHeader = new Croppic('yourId', cropperOptions);
Path to your img crop proccessing file.
var cropperOptions = { cropUrl:'path_to_your_image_cropping_file.php' } var cropperHeader = new Croppic('yourId', cropperOptions);
You will be receiving the following data via AJAX POST method as multipart/form-data;
(note that ajax is limited to same domain requests)
imgUrl // your image path (the one we recieved after successfull upload) imgInitW // your image original width (the one we recieved after upload) imgInitH // your image original height (the one we recieved after upload) imgW // your new scaled image width imgH // your new scaled image height imgX1 // top left corner of the cropped image in relation to scaled image imgY1 // top left corner of the cropped image in relation to scaled image cropW // cropped image width cropH // cropped image heightDownload php example file
After successful image saving, you must return the following json.
( image width and height required for limiting max zoom, so images dont come out blurry. )
{ "status":"success", "url":"path/croppedImg.jpg" }
In case of error response
{ "status":"error", "message":"your error message text" }
Additional data you want to send to your image crop proccessing file
var cropperOptions = { customUploadButtonId:'path_to_your_image_proccessing_file.php', cropData:{ "dummyData":1, "dummyData2":"text" } } var cropperHeader = new Croppic('yourId', cropperOptions);
Load an Image which is already on the Server
var cropperOptions = { cropUrl:'path_to_your_image_cropping_file.php', loadPicture:'path-to-your-image' } var cropperHeader = new Croppic('yourId', cropperOptions);
doubleZoomControls adds two extra zoom controls for 10*zoomFactor zoom (default is true)
zoomFactor zooms the image for the value in pixels (default is 10)
rotateControls adds two extra rotate controls for left and right rotation (default is true)
rotateFactor rotates the image for the value(default is 5)
var cropperOptions = { zoomFactor:10, doubleZoomControls:true, rotateFactor:10, rotateControls:true } var cropperHeader = new Croppic('yourId', cropperOptions);
After successful image cropping, cropped img url is set as value for the input containing the outputUrlId
<input type="text" id="myOutputId">
var cropperOptions = { outputUrlId:'myOutputId' } var cropperHeader = new Croppic('yourId', cropperOptions);
If you want a custom upload img button, just like in the first example here
var cropperOptions = { customUploadButtonId:'myDivId' } var cropperHeader = new Croppic('yourId', cropperOptions);
If you want to open the cropping in modal window (default is false)
var cropperOptions = { modal:true } var cropperHeader = new Croppic('yourId', cropperOptions);
If you want to open the cropping in modal window (default is false)
THE WRAPPING DIV MUST CONTAIN "LOADER" CLASS
var cropperOptions = { loaderHtml:'<img class="loader" src="loader.png" >' } var cropperHeader = new Croppic('yourId', cropperOptions);
If you want to handle the Initial Fileupload in Javascript(Filereader) rather then on Server side (default is false)
NOT ALL BROWSERS SUPPORT THE FILEREADER API: EXAMPLE IE10+ IS SUPPORTED
7 var cropperOptions = { processInline:true, } var cropperHeader = new Croppic('yourId', cropperOptions);
Transparent image showing current img zoom
TIP: to prevent layout breaking, set the parent div of the cropper to "overflow":"hidden"
var cropperOptions = { imgEyecandy:true, imgEyecandyOpacity:0.2 } var cropperHeader = new Croppic('yourId', cropperOptions);
Some callbacks ( open your console and watch the output as you mess arround with the example cropper )
var cropperOptions = { onBeforeImgUpload: function(){ console.log('onBeforeImgUpload') }, onAfterImgUpload: function(){ console.log('onAfterImgUpload') }, onImgDrag: function(){ console.log('onImgDrag') }, onImgZoom: function(){ console.log('onImgZoom') }, onBeforeImgCrop: function(){ console.log('onBeforeImgCrop') }, onAfterImgCrop: function(){ console.log('onAfterImgCrop') }, onReset: function(){ console.log('onReset') }, onError: function(errormsg){ console.log('onError:'+errormsg) } } var cropperHeader = new Croppic('yourId', cropperOptions);
var cropper = new Croppic('yourId', cropperOptions); cropper.destroy() // no need explaining here :) cropper.reset() // destroys and then inits the cropper
- NO PIXELS WERE HARMED DURING THE PRODUCTION OF THIS WEBSITE -