看到一些网站上有图片剪切的功能,觉得挺炫,后来找了一款专用于图片裁切的插件,jquery.jcrop.min.js,用这个插件可以方便的实现这个功能,使用时鼠标在图片上圈选出选区,即可把图片裁切成所选部分,非常适合用于头像的裁切编辑功能。前端ui分享
演示分为html和php两部分:
第一部分,html代码:
.代码
nbsp;html public -//w3c//dtd xhtml 1.0 transitional//en http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd> jcrop实现图片裁剪 #preview{width:100px;height:100px;border:1px solid #000;overflow:hidden;} #imghead{filter:progid:dximagetransform.microsoft.alphaimageloader(sizingmethod=image);} jquery(function(){ jquery('#imghead').jcrop({ aspectratio: 1, onselect: updatecoords, //选中区域时执行对应的回调函数 onchange: updatecoords, //选择区域变化时执行对应的回调函数 }); }); function updatecoords(c) { jquery('#x').val(c.x); //选中区域左上角横 jquery('#y').val(c.y); //选中区域左上角纵坐标 //jquery(#x2).val(c.x2); //选中区域右下角横坐标 //jquery(#y2).val(c.y2); //选中区域右下角纵坐标 jquery('#w').val(c.w); //选中区域的宽度 jquery('#h').val(c.h); //选中区域的高度 }; function checkcoords() { if (parseint(jquery('#w').val())>0) return true; alert('请选择需要裁切的图片区域.'); return false; };
第二部分:php处理部分:jquery分享
.代码
请将上述两部分代码分别另存为两个文件,文件名自拟。