Пример #1
0
 public function actionAvatar()
 {
     if (Yii::app()->request->isPostRequest) {
         if (!intval($_POST['modelID'])) {
             echo "请先上传或选择要剪切的头像图片";
             die;
         }
         $model = File::model()->findByPk($_POST['modelID']);
         //		    $data = UtilHelper::Test($profile->attributes);
         $src = File::model()->generateFileName($model, 'adtheme');
         $desinfo = array('path' => File::model()->generateFileName($model, 'adtheme', true, 120), 'width' => 120, 'height' => 120);
         $x = $_POST['x'];
         $y = $_POST['y'];
         $w = $_POST['w'];
         $h = $_POST['h'];
         $t = new UtilThumbHandle($src);
         $width = $t->getSrcImgWidth();
         $scale = $width / 650;
         $x = round($scale * $x);
         $y = round($scale * $y);
         $w = round($scale * $w);
         $h = round($scale * $h);
         $t->createImg($desinfo, $x, $y, $w, $h);
         $des_120 = File::model()->generateFileName($model, 'adtheme', false, 120);
         echo $des_120;
         die;
     } else {
         UtilHelper::commonWord();
     }
 }
Пример #2
0
 public function actionTest3()
 {
     //		echo Profile::model()->getUserAvatar(Yii::app()->user->id, array(),200);
     $src = './public/20bfaca64c6da0436293e020e62c6d5e1327747695.png';
     $temp = './public/test_temp.jpg';
     $des = './public/test_des.jpg';
     $desinfo = array('path' => $des, 'width' => 150, 'height' => 150);
     $t = new UtilThumbHandle($src);
     $width = $t->getSrcImgWidth();
     $scale = $width / 500;
     $x = 200;
     $y = 5;
     $w = 285;
     $h = 285;
     $x = round($scale * $x);
     $y = round($scale * $y);
     $w = round($scale * $w);
     $h = round($scale * $h);
     $t->createImg($desinfo, $x, $y, $w, $h);
     //		$targ_w = $targ_h = 150;
     //		$jpeg_quality = 90;
     //
     //		$x = 200;
     //		$y = 5;
     //		$w = 285;
     //		$h = 285;
     //
     ////	$src = 'public/uploads/1z2977e09zwss.jpg';
     //		$img_r = imagecreatefromjpeg($src);
     //
     //		$width = imagesx($img_r);
     //
     //		$scale = $width/500;
     //
     //		$x = round($scale*$x);
     //		$y = round($scale*$y);
     //		$w = round($scale*$w);
     //		$h = round($scale*$h);
     //
     //
     //
     //		$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
     //		imagecopyresampled($dst_r,$img_r,0,0,$x,$y,$targ_w,$targ_h,$w,$h);
     //
     //
     //		header('Content-type: image/jpeg');
     //		imagejpeg($dst_r,null,$jpeg_quality);
     //
     //		exit;
     //		$t = new ThumbHandler();
     //	    $t->setSrcImg($src);
     //	    $t->setCutType(1);//指明为手工裁切
     //	    $t->setSrcCutPosition(0, 0);// 源图起点坐标
     //	    $t->setRectangleCut(500, 200);// 裁切尺寸
     //	    $t->setDstImg($temp);
     //	    $t->createImg(500);
     $width = 500;
     $t = new ThumbHandler();
     $t->setSrcImg($src);
     $x = 93;
     $y = 119;
     $w = 252;
     $h = 252;
     $width = $t->getSrcImgWidth();
     $scale = $width / 500;
     $x = round($scale * $x);
     $y = round($scale * $y);
     $w = round($scale * $w);
     $h = round($scale * $h);
     //		$t->setCutType(1);//指明为手工裁切
     //		$t->setDstImg($temp);
     //
     //		$w = $t->getSrcImgWidth();
     //		$h = $t->getSrcImgHeight();
     //
     //		//宽度缩放比例
     //		$num = ($width/$w)*100;
     //
     //		$t->createImg($num);
     //
     //		$t->setSrcImg($temp);
     $t->setCutType(2);
     $t->setDstImg($des);
     $t->setImgDisplayQuality(90);
     $t->setSrcCutPosition($x, $y);
     $t->setRectangleCut(150, 150);
     //		echo $t->_getImgType($src);
     $t->createImg($w, $h);
     //
     ////		unlink($temp);
 }