Example #1
0
 /**
  * 用户通过第三方登陆方式来注册
  * @param String $openid 第三方提供的用户信息唯一标识,一般是保密的
  * @param String $name 第三方提供的昵称信息
  * @param Number $sex 第三方提供用户性别 0 男,1女
  * @param String $avatar_url 第三方提供用户头像url
  * @param String $sign 个性签名
  * @param String $type 第三方类型, 2 微信,3 QQ ,4微博
  * @return Number $uid 注册成功返回的Uid
  */
 public function userRegThroughThird($openid, $name, $sex, $avatar_url, $sign, $type)
 {
     $wechat_auth_str = $type == LOGIN_TYPE_WECHAT ? md5($openid) : '';
     $qq_auth_str = $type == LOGIN_TYPE_QQ ? md5($openid) : '';
     $weibo_auth_str = $type == LOGIN_TYPE_WEIBO ? md5($openid) : '';
     $user_data = array('phone' => 0, 'name' => $name, 'pwd' => '', 'spacebg' => 'files/spacebg/default.jpg', 'sex' => $sex, 'sign' => $sign, 'wechat_auth_str' => $wechat_auth_str, 'qq_auth_str' => $qq_auth_str, 'weibo_auth_str' => $weibo_auth_str, 'regtime' => date('Y-m-d H:i:s'));
     $uid = $this->user->insert($user_data);
     // 这个地方图片头像需要想办法处理一下
     // 生成对应的文件夹
     $path = 'files/avatar/' . date('Ymd') . '/';
     $ori_path = $path . 'ori/';
     $sm_path = $path . 'sm/';
     if (!is_dir($path)) {
         mkdir($path);
         mkdir($ori_path);
         mkdir($sm_path);
     }
     // 头像的处理
     if (!empty($avatar_url)) {
         $filename = date('YmdHis') . rand(0, 9);
         $ori_img_path = $ori_path . $filename . '.jpg';
         $sm_img_path = $sm_path . $filename . '.jpg';
         $round_img_path = $sm_path . $filename . '_round.png';
         $tmp_round_img_path = $sm_path . $filename . '_round_tmp.jpg';
         try {
             // 原图片的存储
             Log::write('begin to download avatar');
             $img = http_get_data($avatar_url);
             Log::write('download ok');
             file_put_contents(SKY_ROOT . $ori_img_path, $img);
             Log::write('save ok');
             // 缩略图的存储
             $ic = new ImgCrop(SKY_ROOT . $ori_img_path, SKY_ROOT . $sm_img_path);
             $ic->Crop(200, 200, 1);
             $ic->SaveImage();
             $ic->destory();
             // round小图的存储,好麻烦
             $ic = new ImgCrop(SKY_ROOT . $ori_img_path, SKY_ROOT . $tmp_round_img_path);
             $ic->Crop(100, 100, 4);
             $ic->SaveImage();
             $ic->destory();
             $rounder = new RoundCorner(SKY_ROOT . $tmp_round_img_path, 50);
             $rounder->round_it(SKY_ROOT . $round_img_path);
             unlink(SKY_ROOT . $tmp_round_img_path);
             $imgs = new Imgs();
             $mid = $imgs->insert(array('uid' => $uid, 'ori' => $ori_img_path, 'sm' => $sm_img_path, 'upload_time' => date('Y-m-d H:i:s')));
             if (!empty($mid)) {
                 $user = new User();
                 $user->update(array('avatar' => $mid), array('uid' => $uid));
             }
         } catch (Exception $e) {
             Log::write('get remote avatar ERR');
         }
     }
     return $uid;
     // 注册成功,返回$uid
 }
Example #2
0
 public function thumb($width = 280, $_dstChar = '')
 {
     //$_dstChar:_m , _s
     if ($this->canUpload && $this->doUpFile != '') {
         $_ext = $this->getExt();
         $_srcImage = $this->directory . $this->doUpFile . "." . $_ext;
         $this->sm_File = $_dstImage = $this->sm_directory . $this->doUpFile . $_dstChar . "." . $_ext;
         $ic = new ImgCrop($_srcImage, $_dstImage);
         $ic->Crop($width, $width, 1);
         $ic->SaveImage();
         $ic->destory();
     }
     /*
     if ($this->canUpload && $this->doUpFile != "") {
     	$_ext = $this->getExt();
     
     
     	$_srcImage = $this->directory.$this->doUpFile.".".$_ext;
     	
     	//得到图片信息数组
     	$_date = getimagesize($_srcImage, $info);
     	
     	$src_w = $_date[0]; //源图片宽
     	$src_h = $_date[1]; //源图片高
     	$src_max_len = max($src_w, $src_h); //求得长边
     	$src_min_len = min($src_w, $src_h); //求得短边
     	$dst_w = ''; //目标图片宽
     	$dst_h = ''; //目标图片高
     	
     	//宽高按比例缩放,最长边不大于$_max_len
     	if ($src_max_len > $_max_len) {
     		$percent = $src_min_len / $src_max_len;
     		if ($src_w == $src_max_len) {
     			$dst_w = $_max_len;
     			$dst_h = $percent * $dst_w;
     		} else {
     			$dst_h = $_max_len;
     			$dst_w = $percent * $dst_h;
     		}
     	} else {
     		$dst_w = $src_w;
     		$dst_h = $src_h;
     	}
     	
     	//建立缩略图时,源图片的位置
     	$src_x = 0;
     	$src_y = 0;
     	
     	//判断如果缩略图用于logo,将对其进行裁减
     	if ('s_' == $_dstChar) {
     		$src_x = $src_w * 0.10;
     		$src_y = $src_h * 0.10;
     		$src_w *= 0.8;
     		$src_h *= 0.8;
     	}
     	
     	//判断图片类型并创建对应新图片
     	switch ($_date[2]) {
     	case 1:
     		$src_im = imagecreatefromgif($_srcImage);
     		break;
     	case 2:
     		$src_im = imagecreatefromjpeg($_srcImage);
     		break;
     	case 3:
     		$src_im = imagecreatefrompng($_srcImage);
     		break;
     	case 8:
     		$src_im = imagecreatefromwbmp($_srcImage);
     		break;
     	}
     	
     	//创建一幅新图像
     	if ($_date[2] == 1) { //gif无法应用imagecreatetruecolor
     		$dst_im = imagecreate($dst_w, $dst_h);
     	} else {
     		$dst_im = imagecreatetruecolor($dst_w, $dst_h);
     	}
     	
     	//对这副图像进行缩略图copy
     	//                        $bg = imagecolorallocate($dst_im,255,255,0);
     	//$dst_im =imagecopyresized($src_im, $src_x, $src_y, $src_w, $src_h );
     	imagecopyresized($dst_im, $src_im, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
     	
     	//对图片进行抗锯齿操作
     	imageantialias($dst_im, true);
     	
     	switch ($_date[2]) {
     	case 1:
     		$cr = imagegif($dst_im, $this->sm_directory.$this->doUpFile.$_dstChar.".".$_ext, 100);
     		break;
     	case 2:
     		$cr = imagejpeg($dst_im, $this->sm_directory.$this->doUpFile.$_dstChar.".".$_ext, 100);
     		break;
     	case 3: //imagepng有问题,所以在这里用imagejpg代替
     		$cr = imagejpeg($dst_im, $this->sm_directory.$this->doUpFile.$_dstChar.".".$_ext, 100);
     		break;
     	}
     	//                        $cr = imagejpeg($dst_im, $this->directory.$_dstChar.$this->doUpFile, 90);
     	if ($cr) {
     		$this->sm_File = $this->sm_directory.$this->doUpFile.$_dstChar.".".$_ext;
     		
     		return $this->sm_File;
     	} else {
     		return false;
     	}
     }
     imagedestroy($dst_im);
     imagedestroy($cr);
     */
 }