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(); } }
public function actionAvatar() { if (Yii::app()->request->isPostRequest) { if (!intval($_POST['modelID'])) { echo "请先上传或选择要剪切的头像图片"; die; } $model = File::model()->findByPk($_POST['modelID']); $profile = Profile::model()->find(array('condition' => 'uid = :uid', 'params' => array(':uid' => Yii::app()->user->id))); if ($profile) { $profile->avatar = $model->id; $profile->save(); } else { UtilHelper::commonWord(); } // $data = UtilHelper::Test($profile->attributes); $src = File::model()->generateFileName($model, 'avatar'); $desinfo = array('path' => File::model()->generateFileName($model, 'avatar', true, 150), 'width' => 150, 'height' => 150); $x = $_POST['x']; $y = $_POST['y']; $w = $_POST['w']; $h = $_POST['h']; $t = new UtilThumbHandle($src); $width = $t->getSrcImgWidth(); $scale = $width / 500; $x = round($scale * $x); $y = round($scale * $y); $w = round($scale * $w); $h = round($scale * $h); $t->createImg($desinfo, $x, $y, $w, $h); $des_60 = File::model()->generateFileName($model, 'avatar', true, 60); $des_30 = File::model()->generateFileName($model, 'avatar', true, 30); if (file_exists($des_30)) { unlink($des_30); } if (file_exists($des_60)) { unlink($des_60); } die; } else { UtilHelper::commonWord(); } }