dev-master
9999999-dev http://fengyuanchen.github.io/cropper/A simple jQuery image cropping plugin
MIT
The Requires
by fengyuanchen
jquery image cropper
A simple jQuery image cropping plugin
A simple jQuery image cropping plugin., (*1)
dist/ โโโ cropper.css ( 5 KB) โโโ cropper.min.css ( 4 KB) โโโ cropper.js (41 KB) โโโ cropper.min.js (17 KB)
Four quick start options are available:, (*2)
git clone https://github.com/fengyuanchen/cropper.git
.npm install cropper
.bower install cropper
.Include files:, (*3)
<script src="/path/to/jquery.js"></script><!-- jQuery is required --> <link href="/path/to/cropper.css" rel="stylesheet"> <script src="/path/to/cropper.js"></script>
Initialize with $.fn.cropper
method., (*4)
<!-- Wrap the image or canvas with a block element --> <div class="container"> <img src="picture.jpg"> </div>
$(".container > img").cropper({ aspectRatio: 16 / 9, done: function(data) { // Output the result data for cropping image. } });
Notes: - The size of the cropper inherits from the size of the image's parent element, so be sure to wrap the image with a visible block element. - The values of the result data was computed with the original size of the image, so you can use them to crop the image directly., (*5)
You may set cropper options with $().cropper(options)
.
If you want to change the global default options, You may use $.fn.cropper.setDefaults(options)
., (*6)
String
| Number
"auto"
The aspect ratio of the cropping zone. By default, the cropping zone is free ratio., (*7)
Object
{}
By default, the cropping zone will appear in the center of the image. If you already have values of the last crop and you want to apply them, just set them as option., (*8)
For example:, (*9)
{ x: 100, y: 50, width: 480, height: 270 }
Function
function(data) {}
This function will be executed when the cropping zone changes by a move, resize or crop., (*10)
""
A jquery selector, add extra elements for a preview., (*11)
Boolean
false
By default, the plugin only supports one cropper per page. If you intend to use more than one, just initialize them with this option set to true
., (*12)
Boolean
true
Show (true) or hide (false) the black modal layer above the cropper., (*13)
Boolean
true
Show (true) or hide (false) the dashed lines above the cropping zone., (*14)
Boolean
true
Render the cropping zone automatically when initialize., (*15)
Number
0.8
A number between 0 and 1. Define the automatic cropping area size (percentage)., (*16)
Boolean
true
Enable to remove the current cropping zone and create a new one by dragging over the image., (*17)
Boolean
true
Enable to move the cropping zone., (*18)
Boolean
true
Enable to resize the cropping zone., (*19)
Boolean
true
Enable to zoom the image., (*20)
Boolean
true
Enable to rotate the image., (*21)
Boolean
true
By default, the plugin will check the image origin, and if it is a cross-origin image, a "crossOrigin" attribute will be added to the image element to enable "rotate" and "getDataURL"., (*22)
Number
0
The minimum width (px of original image) of the cropping zone. Use this option only when you are sure that the image has this minimum width., (*23)
Number
0
The minimum height (px of original image) of the cropping zone. Use this option only when you are sure that the image has this minimum height., (*24)
Number
Infinity
The maximum width (px of original image) of the cropping zone. Use this option only when you are sure that the image has this maximum width., (*25)
Number
Infinity
The maximum height (px of original image) of the cropping zone. Use this option only when you are sure that the image has this maximum height., (*26)
Function
null
An event handler of the "build.cropper" event., (*27)
Function
null
An event handler of the "built.cropper" event., (*28)
Function
null
An event handler of the "dragstart.cropper" event., (*29)
Function
null
An event handler of the "dragmove.cropper" event., (*30)
Function
null
An event handler of the "dragend.cropper" event., (*31)
$().cropper("zoom", 0.1)
or $().cropper("zoom", -0.1)
.$().cropper("rotate", 90)
or $().cropper("rotate", -90)
.crossOrigin
attribute) when it's a cross-origin image.$().cropper("enable")
.$().cropper("disable")
.true
param to reset the cropping zone to the default state.$().cropper("reset")
or $().cropper("reset", true)
.$().cropper("clear")
.$().cropper("replace", "example.jpg")
.$().cropper("destroy")
.rounded
(optional):
Boolean
false
Math.round
.$().cropper("getData")
or $().cropper("getData", true)
.$().cropper("setData", {width: 480, height: 270})
.Tip: If you want to remove the current data, just pass an empty object or null
. For example: $().cropper("setData", {})
or $().cropper("setData", null)
., (*32)
$().cropper("setAspectRatio", 1.618)
.$().cropper("getImageData")
.$().cropper("setDragMode", "crop")
.Tip: You can toggle the "crop" and "move" mode by double click on the image., (*33)
Object
contains: "width", "height". Define the sizes of the result image.String
indicating the image format. The default type is image/png. Other types: "image/jpeg", "image/webp".Number
between 0 and 1 indicating image quality if the requested type is image/jpeg or image/webp.$().cropper("getDataURL") $().cropper("getDataURL", { width: 100, height: 100 }) $().cropper("getDataURL", "image/jpeg") $().cropper("getDataURL", "image/jpeg", 0.8) $().cropper("getDataURL", { width: 100, height: 100 }, "image/jpeg", 0.8)
This event will be fired when the Cropper starts to build., (*34)
This event will be fired when the Cropper has been built., (*35)
This event will be fired before the cropping zone start to move., (*36)
Related events: "mousedown", "touchstart"., (*37)
This event will be fired when the cropping zone was moving., (*38)
Related events: "mousemove", "touchmove"., (*39)
This event will be fired after the cropping zone stop to move., (*40)
Related events: "mouseup", "mouseleave", "touchend", "touchleave", "touchcancel"., (*41)
If you have to use other plugin with the same namespace, just call the $.fn.cropper.noConflict
method to revert to it., (*42)
<script src="other-plugin.js"></script> <script src="cropper.js"></script> <script> $.fn.cropper.noConflict(); // Code that uses other plugin's "$().cropper" can follow here. </script>
As a jQuery plugin, you can reference to the jQuery Browser Support., (*43)
Released under the MIT license., (*44)
A simple jQuery image cropping plugin
MIT
jquery image cropper