首先用到的语言是php、插件imgareaselect(下载地址),没有太多花哨的样式,index.php代码如下: 复制代码 代码如下: <BR>function preview(img, selection) { <BR>$('#selectbanner').data('x',selection.x1); <BR>$('#selectbanner').data('y',selection.y1); <BR>$('#selectbanner').data('w',selection.width); <BR>$('#selectbanner').data('h',selection.height); <br><br>var scaleX = 100 / (selection.width || 1); <BR>var scaleY = 100 / (selection.height || 1); <BR>$('#ferret > img').css({ <BR>width: Math.round(scaleX * 512) + 'px',//512、390是你上传图片的宽高 <BR>height: Math.round(scaleY * 390) + 'px', <BR>marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px', <BR>marginTop: '-' + Math.round(scaleY * selection.y1) + 'px' <BR>}); <BR>} <br><br>//这里通过jQuery语法在原来图片后插入预览的小图片 <BR>$(document).ready(function () { <BR>$('<div id="ferret"><img src="upload_pic/resized_pic.jpg" style="max-width:90%" / alt="php+js实现图片的上传、裁剪、预览、提交示例_PHP教程" ><div>').css({ <BR>float: 'left', <BR>position: 'relative', <BR>overflow: 'hidden', <BR>width: '100px', <BR>height: '100px' <BR>}) <br><br>.insertAfter($('#selectbanner')); <br><br>$('#selectbanner').imgAreaSelect({ <BR>selectionColor: 'blue', x1:0, y1:0, x2: 100,//初始位置 <BR>maxWidth:500,y2:100, <BR>aspectRatio: '1:1',//缩放比例 <BR>selectionOpacity: 0.2 , <BR>onSelectEnd: preview //裁剪后执行的函数,在上面 <BR>}); <BR>//确认裁剪 <BR>$("#sliceButton").click(function() { <BR>var pic = $('#selectbanner').attr('src'); <BR>// alert(pic); <BR>var x,y,w,h; <BR>$.post( <BR>"cat.php", //(2)将附上这个页面的代码 <BR>{ <BR>x:$('#selectbanner').data('x'), <BR>y:$('#selectbanner').data('y'), <BR>w:$('#selectbanner').data('w'), <BR>h:$('#selectbanner').data('h'), <BR>pic:pic <BR>}, <BR>function(data){ <BR>// alert(data); <BR>//把裁剪后图片加载到#sure <BR>if(data){ <BR>$('#sure').attr('src',data); <BR>} <BR>} <BR>); <BR>}); <BR>}) <BR> 图片裁剪、预览 //上传图片后,把图片复制到upload文件夹下面 if($_POST){ $photo = $_FILES['img']['name']; $tmp_addr = $_FILES['img']['tmp_name']; $path = 'upload/'; $type=array("jpg","gif","jpeg","png"); $tool = substr(strrchr($photo,'.'),1); if(!in_array(strtolower($tool),$type)){ $text=implode('.',$type); echo "您只能上传以下类型文件: ",$text,""; }else{ $filename = explode(".",$photo); //把上传的文件名以"."好为准做一个数组。 $time = date("m-d-H-i-s"); //取当前上传的时间 $filename[0] = $time; //取文件名 $name = implode(".",$filename); //上传后的文件名 $uploadfile = $path.$name; $_SESSION['upfile'] = $uploadfile;//上传后的文件名地址 move_uploaded_file($tmp_addr,$uploadfile); } // echo $uploadfile; } ?> if(isset($_SESSION['upfile'])){?> }?> http://www.bkjia.com/PHPjc/313687.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/313687.htmlTechArticle首先用到的语言是php、插件imgareaselect(下载地址),没有太多花哨的样式,index.php代码如下: 复制代码 代码如下: !DOCTYPE html PUBLIC "-//W3C//DTD...