public function actionCropImg() { if (EnvUtil::submitCheck("userSubmit")) { $params = $_POST; if (!isset($params) && empty($params)) { return null; } $tempAvatar = $params["src"]; $avatarPath = "data/avatar/"; $avatarBig = UserUtil::getAvatar($params["uid"], "big"); $avatarMiddle = UserUtil::getAvatar($params["uid"], "middle"); $avatarSmall = UserUtil::getAvatar($params["uid"], "small"); if (LOCAL) { FileUtil::makeDirs($avatarPath . dirname($avatarBig)); } FileUtil::createFile("data/avatar/" . $avatarBig, ""); FileUtil::createFile("data/avatar/" . $avatarMiddle, ""); FileUtil::createFile("data/avatar/" . $avatarSmall, ""); Ibos::import("ext.ThinkImage.ThinkImage", true); $imgObj = new ThinkImage(THINKIMAGE_GD); $imgObj->open($tempAvatar)->crop($params["w"], $params["h"], $params["x"], $params["y"])->save($tempAvatar); $imgObj->open($tempAvatar)->thumb(180, 180, 1)->save($avatarPath . $avatarBig); $imgObj->open($tempAvatar)->thumb(60, 60, 1)->save($avatarPath . $avatarMiddle); $imgObj->open($tempAvatar)->thumb(30, 30, 1)->save($avatarPath . $avatarSmall); $this->success(Ibos::lang("Upload avatar succeed"), $this->createUrl("home/personal", array("op" => "avatar"))); exit; } }
protected function checkAvatar($users) { $avatar = UserUtil::getAvatar($users["uid"]); if (FileUtil::fileExists("data/avatar/" . $avatar)) { return true; } else { return false; } }
public function actionUpload() { if ($_FILES["avatar"]) { $upload = FileUtil::getUpload($_FILES["avatar"]); if (!$upload->save()) { echo "出错了"; } else { $info = $upload->getAttach(); $file = FileUtil::getAttachUrl() . "/" . $info["type"] . "/" . $info["attachment"]; $fileUrl = FileUtil::fileName($file); $uid = Yii::app()->user->uid; $tempAvatar = $file; $avatarPath = "data/avatar/"; $avatarBig = UserUtil::getAvatar($uid, "big"); $avatarMiddle = UserUtil::getAvatar($uid, "middle"); $avatarSmall = UserUtil::getAvatar($uid, "small"); if (LOCAL) { FileUtil::makeDirs($avatarPath . dirname($avatarBig)); } FileUtil::createFile("data/avatar/" . $avatarBig, ""); FileUtil::createFile("data/avatar/" . $avatarMiddle, ""); FileUtil::createFile("data/avatar/" . $avatarSmall, ""); Yii::import("ext.ThinkImage.ThinkImage", true); $imgObj = new ThinkImage(THINKIMAGE_GD); $imgTemp = $imgObj->open($tempAvatar); $params = array("w" => $imgTemp->width(), "h" => $imgTemp->height(), "x" => "0", "y" => "0"); if ($params["h"] < $params["w"]) { $params["x"] = ($params["w"] - $params["h"]) / 2; $params["w"] = $params["h"]; } else { $params["y"] = ($params["h"] - $params["w"]) / 2; $params["h"] = $params["w"]; } $imgObj->open($tempAvatar)->crop($params["w"], $params["h"], $params["x"], $params["y"])->save($tempAvatar); $imgObj->open($tempAvatar)->thumb(180, 180, 1)->save($avatarPath . $avatarBig); $imgObj->open($tempAvatar)->thumb(60, 60, 1)->save($avatarPath . $avatarMiddle); $imgObj->open($tempAvatar)->thumb(30, 30, 1)->save($avatarPath . $avatarSmall); } } }
private function cropImg() { $uid = Ibos::app()->user->uid; $tempAvatar = $_POST["src"]; $avatarPath = "data/avatar/"; $avatarBig = UserUtil::getAvatar($uid, "big"); $avatarMiddle = UserUtil::getAvatar($uid, "middle"); $avatarSmall = UserUtil::getAvatar($uid, "small"); if (LOCAL) { FileUtil::makeDirs($avatarPath . dirname($avatarBig)); } FileUtil::createFile("data/avatar/" . $avatarBig, ""); FileUtil::createFile("data/avatar/" . $avatarMiddle, ""); FileUtil::createFile("data/avatar/" . $avatarSmall, ""); Ibos::import("ext.ThinkImage.ThinkImage", true); $imgObj = new ThinkImage(THINKIMAGE_GD); $imgObj->open($tempAvatar)->thumb(180, 180, 1)->save($avatarPath . $avatarBig); $imgObj->open($tempAvatar)->thumb(60, 60, 1)->save($avatarPath . $avatarMiddle); $imgObj->open($tempAvatar)->thumb(30, 30, 1)->save($avatarPath . $avatarSmall); }