php结合imgareaselect实现图片裁剪_jquery_脚本之家

/js/jquery.imgareaselect-0.9.10/css/imgareaselect-default.css 

/js/jquery.imgareaselect-0.9.10/scripts/jquery.imgareaselect.min.js /js/AjaxFileUploaderV2.1/ajaxfileupload.js



$("#mainimg_src", content).load { crop($; }); function crop { //$img是 //缩小比例 var scalex =$img.width.width(); var scaley =$img.height.height(); $img.imgAreaSelect({ x1:0,y1:0,x2:150,y2:150, handles: true, aspectRatio: '1:1', onSelectEnd: function  { var scaleX = 100 / ; var scaleY = 100 / (selection.height || 1); $.css({ width: Math.round + 'px', height: Math.round + 'px', marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px', marginTop: '-' + Math.round(scaleY * selection.y1) + 'px' }); $('input[name="x1"]', content).val; $('input[name="y1"]', content).val; $('input[name="x2"]', content).val; $('input[name="y2"]', content).val; } }); }

 //确定剪切$("form[name=fmCrop]", content).submit { var data = $("form[name=fmCrop]", content).serializeArray(); $.get('/members/web-members-rest/crop.html', data, function  { switch  { case "Success": jAlert; $.attr("src", "/" + r.path + '?a=' + .format; $("#myPreview", content).css; $("#myPreview", content).prev().css; $.imgAreaSelect; $("form[name=fmUpload]", content).css; $("input[name=btnSubmit]", content).css; break; } }); return false;});

public function actionCrop($src_path,$x1,$x2,$y1,$y2){ $pic =$src_path; $width = $x2-$x1; $height = $y2-$y1; $type=exif_imagetype; //判断文件类型 $support_type=array(IMAGETYPE_JPEG , IMAGETYPE_PNG , IMAGETYPE_GIF); if(!in_array($type, $support_type,true)) { echo "this type of image does not support! only support jpg , gif or png"; exit { case IMAGETYPE_JPEG : $image = imagecreatefromjpeg; break; case IMAGETYPE_PNG : $image = imagecreatefrompng; break; case IMAGETYPE_GIF : $image = imagecreatefromgif; break; default: echo "Load image error!"; exit(); } $copy = $this->PIPHP_ImageCrop($image, $x1, $y1, $width, $height);//裁剪 imagejpeg; //替换新图 return ['result'=>'Success','path'=>$src_path]; //返回新图地址 } function PIPHP_ImageCrop($image, $x, $y, $w, $h){ $tw = imagesx; $th = imagesy; if ($x > $tw || $y > $th || $w > $tw || $h > $th) return FALSE; $temp = imagecreatetruecolor; imagecopyresampled($temp, $image, 0, 0, $x, $y, $w, $h, $w, $h); return $temp; }

以上所述就是本文的全部内容了,希望大家能够喜欢。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

相关文章