function saveThumb()
 {
     //头像大方快的宽高
     $targ_w = 120;
     $targ_h = 120;
     //头像小方块的宽高
     $small_w = 50;
     $small_h = 50;
     //图像质量
     $jpeg_quality = 80;
     $src_arr = explode("?", $_POST['bigImage']);
     $src = $src_arr[0];
     $src = str_ireplace(SITE_URL, '.', $src);
     //获取图片的扩展名。来选择使用什么函数
     if ($arr = @getimagesize($src)) {
         $ext = image_type_to_extension($arr[2], false);
     } else {
         $this->error('对不起,GD库不存在或远程图片不存在');
     }
     $func = $ext != 'jpg' ? 'imagecreatefrom' . $ext : 'imagecreatefromjpeg';
     $img_r = call_user_func($func, $src);
     //开始切割大方块头像
     $dst_r = ImageCreateTrueColor($targ_w, $targ_h);
     $x = $targ_h / $_POST['txt_Zoom'];
     imagecopyresampled($dst_r, $img_r, 0, 0, $_POST['txt_left'] / $_POST['txt_Zoom'], $_POST['txt_top'] / $_POST['txt_Zoom'], $targ_w, $targ_h, $x, $x);
     $path = SITE_PATH . "data/thumb/";
     $filename = $path . 'xxx_s.jpg';
     $face_path = getFacePath($this->mid);
     mkdir($face_path, 0777, true);
     $middle_name = $face_path . $this->mid . "_middle_face.jpg";
     //中图
     imagejpeg($dst_r, $middle_name);
     //生成中图
     imagedestroy($dst_r);
     imagedestroy($img_r);
     $small_name = $face_path . $this->mid . "_small_face.jpg";
     //小图
     vendor("yu_image");
     $img = new yu_image();
     $img->param($middle_name)->thumb($small_name, $small_w, $small_h, 0);
     //缩出小图
     //添加一条动态
     $body_data["src"] = getUserFace($this->mid);
     $this->api->feed_publish("head", $title_data, $body_data);
     setScore($this->mid, 'update_face');
     $this->redirect("/Home/index");
 }
 public function doedit()
 {
     $intId = intval($_REQUEST['id']);
     $pUser = D('User');
     $info = $pUser->where('id=' . $intId)->find();
     if (!$info || !$intId) {
         $this->error('提交错误参数');
         exit;
     }
     switch ($_REQUEST['type']) {
         case 'accounts':
             //帐户设置
             $strEmail = h($_POST['email']);
             $strPassword = h($_POST['password']);
             $map['email'] = $strEmail;
             $map['id'] = array('neq', $intId);
             if (false != $pUser->where($map)->count()) {
                 $this->error("邮箱 {$strEmail} 已存在");
             }
             if ($strPassword) {
                 if (strlen($strPassword) <= 6) {
                     $this->error('密码不能小于6位');
                 } else {
                     $data['password'] = md5($strPassword);
                 }
             }
             $data['email'] = $strEmail;
             $pUser->where('id=' . $intId)->save($data);
             $this->success('修改成功');
             break;
         case 'set':
             //帐号设置
             $intActive = intval($_POST['active']);
             $intLevel = intval($_POST['level']);
             $pUser->setField('active', $intActive, 'id=' . $intId);
             $pUser->setField('admin_level', $intLevel, 'id=' . $intId);
             $this->success('操作成功');
             break;
         case 'cleanface':
             //清空头像
             $path = getFacePath($info['id']);
             @unlink($path . $intId . '_middle_face.jpg');
             @unlink($path . $intId . '_small_face.jpg');
             $this->success('头像清空成功');
             break;
     }
 }
Example #3
0
function getUserFace($uid, $size = 'small')
{
    $size = in_array($size, array('big', 'middle', 'small', "yuan")) ? $size : 'middle';
    $uid = abs(intval($uid));
    $face_path = getFacePath($uid);
    $face_file = $face_path . $uid . "_" . $size . "_face.jpg";
    if (!file_exists($face_file)) {
        //  $face_path =  __PUBLIC__.'/images/noface/';
        //$face_path2  =  C("TS_URL").'/public/images/noface/';
        //$uid       =  "noface";
        $uid = abs(intval($uid));
        $api = new TS_API();
        $info = $api->user_getInfo($uid, "sex");
        if ($info['sex']) {
            return __THEME__ . "/images/pic2.gif";
        } else {
            return __THEME__ . "/images/pic1.gif";
        }
    } else {
        $face_path2 = getFaceUrl($uid);
    }
    return $face_path2 . $uid . "_" . $size . "_face.jpg";
}
 public function set_face()
 {
     //暂时先这么写,应该加到API接口里面去。
     $path = SITE_PATH . "/data/thumb/";
     $filename = $path . 'xxx_s.jpg';
     $face_path = getFacePath($this->mid);
     $middle_name = $face_path . "/" . $this->mid . "_middle_face.jpg";
     //中图
     imagejpeg($dst_r, $middle_name);
     //生成中图
     imagedestroy($dst_r);
     imagedestroy($img_r);
     $small_name = $face_path . "/" . $this->mid . "_small_face.jpg";
     //小图
     vendor("yu_image");
     $img = new yu_image();
     $img->param($middle_name)->thumb($small_name, $small_w, $small_h, 0);
     //缩出小图
     //添加一条动态
     $body_data["src"] = getUserFace($this->mid);
     $this->api->feed_publish("head", $title_data, $body_data);
 }