The [cdnjs](https://github.com/cdnjs/cdnjs) provides CDN support for Cropper's CSS and JavaScript. You can find the links [here](https://cdnjs.com/libraries/cropper).
- The size of the cropper inherits from the size of the image's parent element (wrapper), so be sure to wrap the image with a **visible block element**.
> If you are using cropper in a modal, you should initialize the cropper after the modal shown completely. Otherwise, you will not get a correct cropper.
- The outputted cropped data bases on the original image size, so you can use them to crop the image directly.
- If you try to start cropper on a cross-origin image, please make sure that your browser supports HTML5 [CORS settings attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes), and your image server supports the `Access-Control-Allow-Origin` option (see the [HTTP access control (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS)).
#### Known issues
- [Known iOS resource limits](https://developer.apple.com/library/mac/documentation/AppleApplications/Reference/SafariWebContent/CreatingContentforSafarioniPhone/CreatingContentforSafarioniPhone.html): As iOS devices limit memory, the browser may crash when you are cropping a large image (iPhone camera resolution). To avoid this, you may resize the image first (below 1024px) before start a cropper.
- Known image size increase: When export the cropped image on browser-side with the `HTMLCanvasElement.toDataURL` method, the the exported image'size may be greater than the original image's. This is because the exported image'type is not the same as the original image's. So just pass the original image's type as the first parameter to `toDataURL` to fix this. For example, if the original type is JPEG, then use `$().cropper('getCroppedCanvas').toDataURL('image/jpeg')` to export image.
You may set cropper options with `$().cropper(options)`.
If you want to change the global default options, You may use `$.fn.cropper.setDefaults(options)`.
### viewMode
- Type: `Number`
- Default: `0`
- Options:
-`0`: the crop box is just within the container
-`1`: the crop box should be within the canvas
-`2`: the canvas should not be within the container
-`3`: the container should be within the canvas
Define the view mode of the cropper.
### dragMode
- Type: `String`
- Default: `'crop'`
- Options:
-`'crop'`: create a new crop box
-`'move'`: move the canvas
-`'none'`: do nothing
Define the dragging mode of the cropper.
### aspectRatio
- Type: `Number`
- Default: `NaN`
Set the aspect ratio of the crop box. By default, the crop box is free ratio.
### data
- Type: `Object`
- Default: `null`
The previous cropped data if you had stored, will be passed to `setData` method automatically.
### preview
- Type: `String` (**jQuery selector**)
- Default: `''`
Add extra elements (containers) for previewing.
**Notes:**
- The maximum width is the initial width of preview container.
- The maximum height is the initial height of preview container.
- If you set an `aspectRatio` option, be sure to set the preview container with the same aspect ratio.
- If preview is not getting properly displayed, set `overflow:hidden` to the preview container.
### responsive
- Type: `Boolean`
- Default: `true`
Re-render the cropper when resize the window.
### restore
- Type: `Boolean`
- Default: `true`
Restore the cropped area after resize the window.
### checkCrossOrigin
- Type: `Boolean`
- Default: `true`
Check if the current image is a cross-origin image.
If it is, when clone the image, a `crossOrigin` attribute will be added to the cloned image element and a timestamp will be added to the `src` attribute to reload the source image to avoid browser cache error.
By adding `crossOrigin` attribute to image will stop adding timestamp to image url, and stop reload of image.
### checkOrientation
- Type: `Boolean`
- Default: `true`
Check the current image's Exif Orientation information.
More exactly, read the Orientation value for rotating or flipping the image, and then override the Orientation value with `1` (the default value) to avoid some issues (#120, #509) on iOS devices.
Enable to toggle drag mode between "crop" and "move" when click twice on the cropper.
### minContainerWidth
- Type: `Number`
- Default: `200`
The minimum width of the container.
### minContainerHeight
- Type: `Number`
- Default: `100`
The minimum height of the container.
### minCanvasWidth
- Type: `Number`
- Default: `0`
The minimum width of the canvas (image wrapper).
### minCanvasHeight
- Type: `Number`
- Default: `0`
The minimum height of the canvas (image wrapper).
### minCropBoxWidth
- Type: `Number`
- Default: `0`
The minimum width of the crop box.
**Note:** This size is relative to the page, not the image.
### minCropBoxHeight
- Type: `Number`
- Default: `0`
The minimum height of the crop box.
**Note:** This size is relative to the page, not the image.
### build
- Type: `Function`
- Default: `null`
A shortcut of the "build.cropper" event.
### built
- Type: `Function`
- Default: `null`
A shortcut of the "built.cropper" event.
### cropstart
- Type: `Function`
- Default: `null`
A shortcut of the "cropstart.cropper" event.
### cropmove
- Type: `Function`
- Default: `null`
A shortcut of the "cropmove.cropper" event.
### cropend
- Type: `Function`
- Default: `null`
A shortcut of the "cropend.cropper" event.
### crop
- Type: `Function`
- Default: `null`
A shortcut of the "crop.cropper" event.
### zoom
- Type: `Function`
- Default: `null`
A shortcut of the "zoom.cropper" event.
[⬆ back to top](#table-of-contents)
## Methods
As there is an **asynchronous** process when load the image, you **should call most of the methods after built**, except "setAspectRatio", "replace" and "destroy".
Reset the image and crop box to their initial states.
### clear()
Clear the crop box.
### replace(url[, onlyColorChanged])
- **url**:
- Type: `String`
- A new image url.
- **onlyColorChanged** (optional):
- Type: `Boolean`
- If only change the color, not the size, then the cropper only need to change the srcs of all related images, not need to rebuild the cropper. This can be used for applying filters.
- If not present, its default value is `false`.
Replace the image's src and rebuild the cropper.
### enable()
Enable (unfreeze) the cropper.
### disable()
Disable (freeze) the cropper.
### destroy()
Destroy the cropper and remove the instance from the image.
### move(offsetX[, offsetY])
- **offsetX**:
- Type: `Number`
- Moving size (px) in the horizontal direction.
- **offsetY** (optional):
- Type: `Number`
- Moving size (px) in the vertical direction.
- If not present, its default value is `offsetX`.
Move the canvas (image wrapper) with relative offsets.
```js
$().cropper('move', 1);
$().cropper('move', 1, 0);
$().cropper('move', 0, -1);
```
### moveTo(x[, y])
- **x**:
- Type: `Number`
- The `left` value of the canvas
- **y** (optional):
- Type: `Number`
- The `top` value of the canvas
- If not present, its default value is `x`.
Move the canvas (image wrapper) to an absolute point.
### zoom(ratio)
- **ratio**:
- Type: `Number`
- Zoom in: requires a positive number (ratio > 0)
- Zoom out: requires a negative number (ratio <0)
Zoom the canvas (image wrapper) with a relative ratio.
```js
$().cropper('zoom', 0.1);
$().cropper('zoom', -0.1);
```
### zoomTo(ratio)
- **ratio**:
- Type: `Number`
Zoom the canvas (image wrapper) to an absolute ratio.
> After then, you can display the canvas as an image directly, or use [HTMLCanvasElement.toDataURL](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL) to get a Data URL, or use [HTMLCanvasElement.toBlob](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob) to get a blob and upload it to server with [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) if the browser supports these APIs.