码迷,mamicode.com
首页 > 其他好文 > 详细

前端裁切图片插件之cropper介绍

时间:2017-01-12 13:02:32      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:query   idt   graphics   地址   console   https   后台   class   技术分享   

  给大家介绍一个前端非常实用的依赖于jquery的图片裁切插件cropper.

  因为前端无法做到图片的裁切,所以实际中需要用cropper和后台的GraphicsMagick相互配合.

  先贴上cropper的网址https://fengyuanchen.github.io/cropperjs/和github地址:https://github.com/fengyuanchen/cropper 

  第一步:下载cropper:

  

npm install cropper.

  第二部:引入依赖包和插件包:

  

<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>

  第三部:在js中调用方法:

$(‘#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);
  }
});

  其中aspectRatio 是指图片的长宽比

  只需要将x,y,width,height,rotate,scaleX,scaleY这些数据传给后台,后台就可以根据数据进行图片的裁切.

  使用cropper要注意一点,这个插件会在dom中构建一些标签,所以在图片展示的时候多注意:

  

  技术分享

 

前端裁切图片插件之cropper介绍

标签:query   idt   graphics   地址   console   https   后台   class   技术分享   

原文地址:http://www.cnblogs.com/H5C3XXN/p/6275758.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!