/** * 修改截取后的头像 */ public function ModifyAvator() { $ShearPhoto["config"] = array("proportional" => 0); import('Vendor.ShearPhoto.ShearPhoto'); $Shear = new \ShearPhoto(ACPopedom::mixPass(ACPopedom::getID())); $tmp_name = $Shear->run(json_decode(trim(stripslashes($_POST["JSdate"])), true), $ShearPhoto["config"]); //传入参数运行 if (!$tmp_name) { $this->ajaxReturn(array('erro' => '头像保存失败')); } $filename = $Shear->filename . $Shear->imagesuffix; //又拍云上传 import('Vendor.Upyun.UpYunApi'); $upYunApi = new \UpYunApi(UPYUN_BUCKET, UPYUN_USERNAME, UPYUN_PASSWORD); $upYunApi->debug = false; $upYunApi->setApiDomain(UPYUN_HOST); $fh = fopen($tmp_name, 'rb'); $rsp = $upYunApi->writeFile('/Attachment/face/' . $filename, $fh, true); if (file_exists(ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . $Shear->filename)) { unlink(ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . $filename); } fclose($fh); if ($rsp) { $result = M('Users')->where('userid = ' . ACPopedom::getID())->save(array('avator' => UPYUN_BASIC_URL . '/Attachment/face/' . $filename)); if ($result !== false) { $userinfo = ACPopedom::getUserInfo(); cookie("__info__", authcode(serialize(array('nickname' => $userinfo['nickname'], 'userid' => $userinfo['userid'], 'avator' => UPYUN_BASIC_URL . '/Attachment/face/' . $filename)), "ENCODE", SESSION_AUTH, C('COOKIE_EXPIRE'))); $this->ajaxReturn(array('success' => '截图成功!如不能立即显示,请多刷新两次', 'url' => U('Web/UserCenter/index'))); } else { $this->ajaxReturn(array('erro' => '头像更新失败')); } } else { $this->ajaxReturn(array('erro' => '头像更新失败')); } }
public function cutp() { $ShearPhoto["config"] = $this->init(); $ShearPhoto["JSdate"] = isset($_POST["JSdate"]) ? json_decode(trim(stripslashes($_POST["JSdate"])), true) : die('{"erro":"致命错误"}'); $Shear = new ShearPhoto(); //类实例开始 $result = $Shear->run($ShearPhoto["JSdate"], $ShearPhoto["config"]); //传入参数运行 if ($result === false) { //切图失败时 echo '{"erro":"' . $Shear->erro . '"}'; //把错误发给JS /请匆随意更改"erro"的编写方式,否则JS出错 } else { $dirname = pathinfo($ShearPhoto["JSdate"]["url"]); $ShearPhotodirname = $dirname["dirname"] . DIRECTORY_SEPARATOR . "shearphoto.lock"; //认证删除的密钥 file_exists(SITE_PATH . $ShearPhotodirname) && @unlink($ShearPhoto["JSdate"]["url"]); //密钥存在,当然就删掉原图 //保存数据到数据库 foreach ($result as $key => $val) { $result[$key]['status'] = 1; $imgurl = str_replace(array('./', '\\', __ROOT__), array('/', '/', ''), $val['ImgUrl']); $data['path'] = $imgurl; $data['sha1'] = sha1_file(); $data['thumbpath'] = $imgurl; $data['destname'] = $val['ImgName']; $data['srcname'] = $val['ImgName']; $data['create_time'] = time(); $data['uid'] = UID; $model = M('picture'); if ($model->create($data)) { $re = $model->add($data); if ($re > 0) { $result[$key]['id'] = $re; } } } $result = json_encode($result); echo str_replace(array("\\\\", "\\/", ShearURL, "\\", './'), array("\\", "/", "", "/", '/'), $result); //去掉无用的字符修正URL地址,再把数据传弟给JS /* 到此程序已运行完毕,并成功!你可以在这里愉快地写下你的逻辑代码 $result[X]["ImgUrl"] //图片路径 X是数字 $result[X]["ImgName"] //图片文件名字 X是数字 $result[X]["ImgWidth"]//图片宽度 X是数字 $result[X]["ImgHeight"] //图片高度 X是数字 用var_dump($result)展开,你便一目了然! */ } die; }
} return $arr; } protected function compression($DigShear, $PHPconfig, $w, $h, $type, $strtype, $JSconfig) { require 'zip_img.php'; $arrimg = $this->CreateArray($PHPconfig, $JSconfig, $strtype); if (!$arrimg) { return false; } $zip_photo = new zip_img(array("dest" => $DigShear, "water" => $PHPconfig["water"], "water_scope" => $PHPconfig["water_scope"], "w" => $w, "h" => $h, "type" => $type, "strtype" => $strtype, "zip_array" => $arrimg)); return $zip_photo->run(); } } //类结束 $Shear = new ShearPhoto(); //类实例开始 $result = $Shear->run($ShearPhoto["JSdate"], $ShearPhoto["config"]); //传入参数运行 if ($result === false) { //切图失败时 echo '{"erro":"' . $Shear->erro . '"}'; //把错误发给JS /请匆随意更改"erro"的编写方式,否则JS出错 } else { $dirname = pathinfo($ShearPhoto["JSdate"]["url"]); $ShearPhotodirname = $dirname["dirname"] . DIRECTORY_SEPARATOR . "shearphoto.lock"; //认证删除的密钥 file_exists($ShearPhotodirname) && @unlink($ShearPhoto["JSdate"]["url"]); //密钥存在,当然就删掉原图 $result = json_encode($result); echo str_replace(array("\\\\", "\\/", ShearURL, "\\"), array("\\", "/", "", "/"), $result);
$result = $Shear->run($ShearPhoto["JSdate"], $ShearPhoto["config"]); //传入参数运行 if ($result === false) { //切图失败时 echo '{"erro":"' . $Shear->erro . '"}'; //把错误发给JS /请匆随意更改"erro"的编写方式,否则JS出错 exit; } else { $dirname = pathinfo($ShearPhoto["JSdate"]["url"]); $ShearPhotodirname = $dirname["dirname"] . DIRECTORY_SEPARATOR . "shearphoto.lock"; //认证删除的密钥 file_exists($ShearPhotodirname) && @unlink($ShearPhoto["JSdate"]["url"]); //密钥存在,当然就删掉原图 } } elseif (isset($_POST["ShearPhotoIW"]) && isset($_POST["ShearPhotoIH"]) && isset($_POST["ShearPhotoFW"]) && isset($_POST["ShearPhotoFH"]) && isset($_POST["ShearPhotoP"]) && is_numeric($JSconfig["P"] = trim($_POST["ShearPhotoP"])) && is_numeric($JSconfig["IW"] = trim($_POST["ShearPhotoIW"])) && is_numeric($JSconfig["IH"] = trim($_POST["ShearPhotoIH"])) && is_numeric($JSconfig["FW"] = trim($_POST["ShearPhotoFW"])) && is_numeric($JSconfig["FH"] = trim($_POST["ShearPhotoFH"]))) { $Shear = new ShearPhoto(); //类实例开始 $result = $Shear->html5_run($ShearPhoto["config"], $JSconfig); //加载HTML5已切好的图片独有方法 if ($result === false) { //切图失败时 echo '{"erro":"' . $Shear->erro . '"}'; //把错误发给JS /请匆随意更改"erro"的编写方式,否则JS出错 exit; } } else { die('{"erro":"错误的操作!或缺少参数或错误参数"}'); } /*........错误的操作................*/ /*..........................................................结果输出给JS..............................................................*/ /*