( open in modal window )
( display url after cropping )
( no background image )
Simplest implementation. Beware that you must provide width and height of the container.
var cropperHeader = new Crop('yourId');
<div id="yourId"></div>
#cropContainerHeader { width: 200px; height: 150px; position:relative; /* or fixed or absolute */ }
Path to your img upload proccessing file.
var cropperHeader = new Crop('yourId', cropperOptions); var cropperOptions = { uploadUrl:'path_to_your_image_proccessing_file.php' }
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 cropperHeader = new Crop('yourId', cropperOptions); var cropperOptions = { uploadUrl:'path_to_your_image_proccessing_file.php', uploadData:{ "dummyData":1, "dummyData2":"text" } }
Path to your img crop proccessing file.
var cropperHeader = new Crop('yourId', cropperOptions); var cropperOptions = { cropUrl:'path_to_your_image_cropping_file.php' }
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 cropperHeader = new Crop('yourId', cropperOptions); var cropperOptions = { customUploadButtonId:'path_to_your_image_proccessing_file.php', cropData:{ "dummyData":1, "dummyData2":"text" } }
After successful image cropping, cropped img url is set as value for the input containing the outputUrlId
<input type="text" id="myOutputId">
var cropperHeader = new Crop('yourId', cropperOptions); var cropperOptions = { outputUrlId:'myOutputId' }
If you want a custom upload img button, just like in the first example here
var cropperHeader = new Crop('yourId', cropperOptions); var cropperOptions = { customUploadButtonId:'myDivId' }
If you want to open the cropping in modal window (default is false)
var cropperHeader = new Crop('yourId', cropperOptions); var cropperOptions = { modal:true }
If you want to open the cropping in modal window (default is false)
THE WRAPPING DIV MUST CONTAIN "LOADER" CLASS
var cropperHeader = new Crop('yourId', cropperOptions); var cropperOptions = { loaderHtml:'<img class="loader" src="loader.png" >' }
Transparent image showing current img zoom
TIP: to prevent layout breaking, set the parent div of the cropper to "overflow":"hidden"
var cropperHeader = new Crop('yourId', cropperOptions); var cropperOptions = { imgEyecandy:true, imgEyecandyOpacity:0.2 }
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)
var cropperHeader = new Crop('yourId', cropperOptions); var cropperOptions = { zoomFactor:10, doubleZoomControls:true }
Some callbacks ( open your console and watch the output as you mess arround with the example cropper )
var cropperHeaderOptions = { 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') } }
var cropper = new Crop('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 -