コード例 #1
0
ファイル: common_helper.php プロジェクト: ruoL/fun-x
function get_avatar($uid, $size = 48)
{
    $size = in_array($size, array('160', '100', '48')) ? $size : '48';
    $path = config_item('site_attach_dir') . DIRECTORY_SEPARATOR . 'avatar' . DIRECTORY_SEPARATOR;
    $avatar = build_dir($uid) . $uid . '_' . $size . '.png';
    if (@is_file(FCPATH . $path . $avatar) === true) {
        return base_url($path . $avatar);
    } else {
        return base_url($path . build_dir(0) . '0_' . $size . '.png');
    }
}
コード例 #2
0
ファイル: Action.php プロジェクト: ruoL/fun-x
 /**
  * 从硬盘删除文章头图
  * 
  * @access public
  * @params int $aid 文章ID
  * @return NULL
  */
 public function unlink_article_image($aid)
 {
     $aid = (int) $aid;
     $size = array(160, 48);
     $path = config_item('site_attach_dir') . DIRECTORY_SEPARATOR . 'article' . DIRECTORY_SEPARATOR;
     foreach ($size as $v) {
         $image = FCPATH . $path . build_dir($aid) . $aid . '_' . $v . '.png';
         if (@is_file($image) === true) {
             @chmod($image, 0777);
             @unlink($image);
         }
     }
 }
コード例 #3
0
ファイル: huangye.php プロジェクト: ruoL/fun-x
 public function crop_image_action()
 {
     $x = (int) $this->input->get('x');
     $y = (int) $this->input->get('y');
     $w = (int) $this->input->get('w');
     $h = (int) $this->input->get('h');
     if ($w < 100 or $h < 100) {
         JSON('error', '请选择一个合适的图像区域!');
     }
     $hid = (int) $this->input->get('hid');
     $imagepath = $this->input->get('path', true);
     $imagepath = FCPATH . str_replace(base_url(), '', $imagepath);
     if (empty($imagepath) or @is_file($imagepath) === false) {
         JSON('error', '找不到需要裁切的图片!');
     }
     $imageinfo = pathinfo($imagepath);
     switch ($imageinfo['extension']) {
         case 'jpg':
         case 'jpeg':
             $image = imagecreatefromjpeg($imagepath);
             break;
         case 'png':
             $image = imagecreatefrompng($imagepath);
             break;
         case 'gif':
             $image = imagecreatefromgif($imagepath);
             break;
         default:
             JSON('error', '您上传的文件格式不正确!');
     }
     $copy = $this->_image_crop($image, $x, $y, $w, $h);
     if ($copy === false) {
         JSON('error', '未知错误,请重试!');
     }
     $temppath = FCPATH . $this->_attach_dir . 'huangye' . DIRECTORY_SEPARATOR . build_dir($hid);
     if (@is_dir($temppath) === false) {
         create_dir($temppath);
     }
     if (@is_writable($temppath) === false) {
         @chmod($temppath, 0777);
     }
     $savepath = $temppath . $hid . '.png';
     imagepng($copy, $savepath);
     imagedestroy($copy);
     $this->load->library('image_lib');
     list($width, $height, $type, $attr) = getimagesize($savepath);
     $array = array(array('w' => 100, 'h' => 100), array('w' => 50, 'h' => 50));
     foreach ($array as $size) {
         if ($width > $size['w'] or $height > $size['h']) {
             $setwidth = $size['w'];
             $setheight = $size['h'];
         } else {
             $setwidth = $width;
             $setheight = $height;
         }
         $config['source_image'] = $savepath;
         $config['new_image'] = $hid . '_h' . $size['w'] . '.png';
         $config['height'] = $setheight;
         $config['width'] = $setwidth;
         $this->image_lib->initialize($config);
         $this->image_lib->resize();
     }
     $show_img = 'http://weinan.fun-x.cn/attach/huangye/00/01/' . $hid . '_h100.png';
     $data_img = array('img_url' => $show_img);
     $this->db->where('hid', $hid);
     $this->db->update('huangye', $data_img);
     unlink($imagepath);
     unlink($savepath);
     JSON('success', '头图已保存成功!', $show_img);
 }