示例#1
0
 public function generateUserAvatars($model, $size = 60, $path = 'avatar')
 {
     $origion = File::model()->generateFileName($model, $path, true);
     $src = File::model()->generateFileName($model, $path, true, 150);
     $des = File::model()->generateFileName($model, $path, true, $size);
     if (!file_exists($des)) {
         if (!is_dir(dirname($des))) {
             UtilHelper::createFolder(dirname($des));
         }
         if (file_exists($src)) {
             $t = new ThumbHandler();
             $t->setSrcImg($src);
             $t->setCutType(1);
             //指明为手工裁切
             //			    $t->setSrcCutPosition(100, 100);// 源图起点坐标
             $t->setRectangleCut($size, $size);
             // 裁切尺寸
             $t->setImgDisplayQuality(90);
             $t->setDstImg($des);
             $t->createImg(150, 150);
         } elseif (file_exists($origion)) {
             $t = new ThumbHandler();
             $t->setSrcImg($origion);
             $t->setCutType(2);
             $t->setSrcCutPosition(0, 0);
             $t->setRectangleCut($size, $size);
             $t->setImgDisplayQuality(90);
             $t->setDstImg($des);
             $width = $t->getSrcImgWidth();
             $height = $t->getSrcImgHeight();
             if ($width >= $height) {
                 $t->createImg($height, $height);
             } else {
                 $t->createImg($width, $width);
             }
         }
     }
 }
 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);
 }