A simple jQuery image cropping plugin.
Website Cropper without jQuery
dist/ ├── cropper.css ( 5 KB) ├── cropper.min.css ( 4 KB) ├── cropper.js (78 KB) └── cropper.min.js (28 KB)
Four quick start options are available:
Download the latest release. Clone the repository: git clone https://github.com/fengyuanchen/cropper.git. Install with NPM: npm install cropper. Install with Bower: bower install cropper.Include files:
<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>
The cdnjs provides CDN support for Cropper's CSS and JavaScript. You can find the links here.
Initialize with $.fn.cropper method.
<!-- Wrap the image or canvas element with a block element (container) --> <div> <img id="image" src="picture.jpg"> </div>
/* Limit image width to avoid overflow the container */ img { max-width: 100%; /* This rule is very important, please do not ignore this! */ }
$('#image').cropper({ aspectRatio: 16 / 9, crop: function(e) { // Output the result data for cropping image. console.log(e.x); console.log(e.y); console.log(e.width); console.log(e.height); console.log(e.rotate); console.log(e.scaleX); console.log(e.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 crop 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.
NotesThe 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, and your image server supports the Access-Control-Allow-Origin option (see the HTTP access control (CORS)).
Known issuesKnown iOS resource limits: 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 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 type the original image's 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
You may set cropper options with $().cropper(options). If you want to change the global default options, You may use $.fn.cropper.setDefaults(options).
Define the view mode of the cropper.
Define the dragging mode of the cropper.
Set the aspect ratio of the crop box. By default, the crop box is free ratio.
The previous cropped data if you had stored, will be passed to setData method automatically.
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.Re-render the cropper when resize the window.
Restore the cropped area after resize the window.
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.
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.
Requires to set both the rotatable and scalable options to true at the same time.
Note: Don't trust this all the time as some JPG images have incorrect (not standard) Orientation values.
Requires Typed Arrays support (IE 10+).
Show the black modal above the image and under the crop box.
Show the dashed lines above the crop box.
Show the center indicator above the crop box.
Show the white modal above the crop box (highlight the crop box).
相关知识
ssm框架鲜花完整项目前台后台实现包含sql
【计算机毕业设计】7.线上花店系统maven源码
Java毕业设计基于Springboot+vue的鲜花销售商城网站
基于WEB的花卉养殖知识平台的设计与实现
[开题报告]FLASK框架鲜花售卖网站的设计与实现p9wlm(源码+论文)
鲜花售卖网站的设计与实现(源码+开题报告)
鲜花花卉管理系统.zip
基于SSM花卉商城设计与实现
springboot毕设项目网上鲜花销售系统6r845(java+VUE+Mybatis+Maven+Mysql)
ASP.NET网上鲜花销售系统的设计
网址: ssm框架鲜花完整项目前台后台实现包含sql https://m.huajiangbk.com/newsview33752.html
上一篇: 第五届福建文学好书榜上榜图书展示 |
下一篇: 我校学子在安徽省第九届茉莉花全民 |