# Cropper.js
[![Build Status](https://img.shields.io/travis/fengyuanchen/cropperjs.svg)](https://travis-ci.org/fengyuanchen/cropperjs) [![Downloads](https://img.shields.io/npm/dm/cropperjs.svg)](https://www.npmjs.com/package/cropperjs) [![Version](https://img.shields.io/npm/v/cropperjs.svg)](https://www.npmjs.com/package/cropperjs) [![Gzip Size](https://img.shields.io/bundlephobia/minzip/cropperjs.svg)](https://unpkg.com/cropperjs/dist/cropper.common.js) [![Dependencies](https://img.shields.io/david/fengyuanchen/cropperjs.svg)](https://www.npmjs.com/package/cropperjs)
> JavaScript image cropper.
- [Website](https://fengyuanchen.github.io/cropperjs)
- [Photo Editor](https://fengyuanchen.github.io/photo-editor) - An advanced example of Cropper.js.
- [jquery-cropper](https://github.com/fengyuanchen/jquery-cropper) - A jQuery plugin wrapper for Cropper.js.
## Table of contents
- [Features](#features)
- [Main](#main)
- [Getting started](#getting-started)
- [Options](#options)
- [Methods](#methods)
- [Events](#events)
- [No conflict](#no-conflict)
- [Browser support](#browser-support)
- [Contributing](#contributing)
- [Versioning](#versioning)
- [License](#license)
## Features
- Supports 39 [options](#options)
- Supports 27 [methods](#methods)
- Supports 6 [events](#events)
- Supports touch (mobile)
- Supports zooming
- Supports rotating
- Supports scaling (flipping)
- Supports multiple croppers
- Supports to crop on a canvas
- Supports to crop an image in the browser-side by canvas
- Supports to translate Exif Orientation information
- Cross-browser support
## Main
```text
dist/
├── cropper.css
├── cropper.min.css (compressed)
├── cropper.js (UMD)
├── cropper.min.js (UMD, compressed)
├── cropper.common.js (CommonJS, default)
└── cropper.esm.js (ES Module)
```
## Getting started
### Installation
```shell
npm install cropperjs
```
In browser:
```html
<link href="/path/to/cropper.css" rel="stylesheet">
<script src="/path/to/cropper.js"></script>
```
[cdnjs](https://github.com/cdnjs/cdnjs) provides CDN support for Cropper.js's CSS and JavaScript. You can find the links [here](https://cdnjs.com/libraries/cropperjs).
### Usage
#### Syntax
```js
new Cropper(element[, options])
```
- **element**
- Type: `HTMLImageElement` or `HTMLCanvasElement`
- The target image or canvas element for cropping.
- **options** (optional)
- Type: `Object`
- The options for cropping. Check out the available [options](#options).
#### Example
```html
<!-- Wrap the image or canvas element with a block element (container) -->
<div>
<img id="image" src="picture.jpg">
</div>
```
```css
/* Ensure the size of the image fit the container perfectly */
img {
display: block;
/* This rule is very important, please don't ignore this */
max-width: 100%;
}
```
```js
// import 'cropperjs/dist/cropper.css';
import Cropper from 'cropperjs';
const image = document.getElementById('image');
const cropper = new Cropper(image, {
aspectRatio: 16 / 9,
crop(event) {
console.log(event.detail.x);
console.log(event.detail.y);
console.log(event.detail.width);
console.log(event.detail.height);
console.log(event.detail.rotate);
console.log(event.detail.scaleX);
console.log(event.detail.scaleY);
},
});
```
#### FAQ
How to crop a new area after zoom in or zoom out?
> Just double-click your mouse to enter crop mode.
How to move the image after cropping an area?
> Just double click your mouse to enter move mode.
How to fix aspect ratio in free ratio mode?
> Just hold the `Shift` key when you resize the crop box.
How to crop a square area in free ratio mode?
> Just hold the `Shift` key when you crop on the image.
#### Notes
- 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 is shown completely. Otherwise, you will not get the correct cropper.
- The outputted cropped data is based 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 (preferably below 1024 pixels) before starting a cropper.
- Known image size increase: When exporting the cropped image on the browser side with the `HTMLCanvasElement.toDataURL` method, the size of the exported image may be greater than the original image's. This is because the type of the exported image 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.
[⬆ back to top](#table-of-contents)
## Options
You may set cropper options with `new Cropper(image, options)`.
If you want to change the global default options, You may use `Cropper.setDefaults(options)`.
### viewMode
- Type: `Number`
- Default: `0`
- Options:
- `0`: no restrictions
- `1`: restrict the crop box not to exceed the size of the canvas.
- `2`: restrict the minimum canvas size to fit within the container. If the proportions of the canvas and the container differ, the minimum canvas will be surrounded by extra space in one of the dimensions.
- `3`: restrict the minimum canvas size to fill fit the container. If the proportions of the canvas and the container are different, the container will not be able to fit the whole canvas in one of the dimensions.
Define the view mode of the cropper. If you set `viewMode` to `0`, the crop box can extend outside the canvas, while a value of `1`, `2`, or `3` will restrict the crop box to the size of the canvas. `viewMode` of `2` or `3` will additionally restrict the canvas to the container. There is no difference between `2` and `3` when the proportions of the canvas and the container are the same.
### 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.
### initialAspectRatio
- Type: `Number`
- Default: `NaN`
Define the initial aspect ratio of the crop box. By default, it is the same as the aspect ratio of the canvas (image wrapper).
> Only available when the `aspectRatio` option is set to `NaN`.
### aspectRatio
- Type: `Number`
- Default: `NaN`
Define the fixed aspect ratio of the crop box. By default, the crop box has a free ratio.
### data
- Type: `Object`
- Default: `null`
The previous cropped data you stored will be passed to the `setData` method automatically when initialized.
> Only available when the `autoCrop` option had set to the`true`.
### preview
- Type: `Element`, `Array` (elements), `NodeList` or `String` (selector)
- Default: `''`
- An element or an array of elements or a node list object or a valid selector for [Document.querySelectorAll](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll)
Add extra elements (containers) for preview.
**Notes:**
- The maximum width is the initial width of the preview container.
- The maximum height is the initial height of the preview container.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 Python毕业设计-基于Django的跳蚤市场网站的设计与实现+使用说明+全部资料(优秀项目).zipPython毕业设计-基于Django的跳蚤市场网站的设计与实现+使用说明+全部资料(优秀项目).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如软件工程、计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也可作为毕设项目、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 3、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
Python毕业设计-基于Django的跳蚤市场网站的设计与实现+使用说明+全部资料(优秀项目).zip (221个子文件)
sync.bat 60B
start.bat 39B
goods_detail.css 11KB
self.css 8KB
goods_list.css 5KB
common.css 5KB
chat.css 5KB
cropper.css 5KB
cropper.css 4KB
message.css 4KB
cropper.min.css 4KB
new_goods.css 3KB
login.css 3KB
index.css 3KB
base.css 1KB
system_msg.css 1KB
error.css 345B
index.css 29B
sqlite3.db 204KB
icomoon.eot 23KB
.gitignore 106B
error_msg.html 19KB
goods_detail.html 14KB
self.html 10KB
chat.html 9KB
goods_list.html 7KB
new_goods.html 5KB
message.html 5KB
index.html 5KB
login.html 3KB
printer.html 2KB
system_msg.html 2KB
edit_goods.html 568B
favicon.ico 9KB
jquery.js 282KB
jquery.slim.js 230KB
cropper.js 111KB
cropper.common.js 105KB
cropper.esm.js 105KB
jquery.min.js 87KB
jquery.slim.min.js 71KB
sizzle.js 69KB
cropper.min.js 36KB
utilities.js 24KB
event.js 24KB
ajax.js 22KB
methods.js 20KB
sizzle.min.js 20KB
effects.js 17KB
render.js 15KB
css.js 14KB
manipulation.js 12KB
cropper.js 11KB
change.js 11KB
deferred.js 11KB
core.js 9KB
offset.js 7KB
selector-native.js 6KB
callbacks.js 5KB
trigger.js 5KB
handlers.js 5KB
support.js 5KB
traversing.js 5KB
classes.js 4KB
xhr.js 4KB
data.js 4KB
val.js 4KB
Data.js 4KB
preview.js 4KB
init.js 3KB
Tween.js 3KB
attr.js 3KB
serialize.js 3KB
queue.js 3KB
prop.js 3KB
index.js 3KB
events.js 3KB
constants.js 3KB
jsonp.js 3KB
buildFragment.js 2KB
findFilter.js 2KB
defaults.js 2KB
showHide.js 2KB
ready-no-deferred.js 2KB
deprecated.js 2KB
ready.js 2KB
adjustCSS.js 2KB
load.js 2KB
safe.js 2KB
dimensions.js 2KB
focusin.js 2KB
curCSS.js 2KB
script.js 2KB
parseHTML.js 2KB
wrap.js 1KB
template.js 1KB
access.js 1KB
isHiddenWithinTree.js 1KB
support.js 1KB
DOMEval.js 1KB
共 221 条
- 1
- 2
- 3
资源评论
不走小道
- 粉丝: 3228
- 资源: 5113
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- ThinkPHP5多小区物业管理系统源码PHP物业管理系统.zip
- 基于flask,Navicat和爬虫的可视化岗位分析网站.zip
- 部署yolov10的ncnn模型到android源码+模型+项目说明.zip
- Go语言网络层脚手架代码资料项目间共用的网络层.zip
- 基于monaco-editor的sql编辑器,支持sql语法联想、高亮.zip
- 网络安全相关的RSS订阅列表资料.zip
- 用Vue.js开发微信app项目源代码资料.zip
- 基于YOLO-V4算法与Pytorch的视频多目标跟踪系统的开发.zip
- 雾霾分析的MATLAB GUI仿真程序.zip
- 基于react的618节日网页全屏祝福.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功