Beispiel #1
0
 /**
  * 文件不存在时转向到此方法 创建缩略图
  *
  * 源文件不存在 显示默认图  font/indexbg.jpg
  * 应用自定义默认图放在 font/{$app_uniqueid}/indexbg.jpg
  *
  * @param host string
  * @param refer_to string required 文件路径
  *      如material/news/img/100x75/2012/05/20120529143609jSG7.jpg?21jj
  */
 function create()
 {
     $url = urldecode($this->input['refer_to']);
     $host = urldecode($this->input['host']);
     //$url = 'material/news/img/100x75/2012/05/20120529143609jSG7.jpg?21jj';
     if (empty($url) || empty($host)) {
         $this->readfile(CUR_CONF_PATH . 'font/indexbg.jpg', 'indexbg.jpg');
     } else {
         preg_match_all('/^\\/(.*?\\/.*?\\/)?(.*?\\/img\\/)([0-9]*)[x|-]([0-9]*)\\/(\\d{0,4}\\/\\d{0,2}\\/)(.*?)(\\.[a-zA-Z0-9_]*)(\\?\\w*)?/i', $url, $out);
         $tmp = explode('/', $out[2][0]);
         if ($tmp[0] == 'material') {
             $app_uniqueid = $tmp[1];
         } else {
             $app_uniqueid = $tmp[0];
         }
         $info = array('host' => $host, 'dir' => $out[2][0], 'filepath' => $out[5][0], 'filename' => $out[6][0], 'type' => $out[7][0], 'app_uniqueid' => $app_uniqueid);
         $size = array('label' => $out[3][0] . 'x' . $out[4][0], 'width' => $out[3][0], 'height' => $out[4][0], 'other_dir' => $out[5][0]);
         $IMG_DIR = $this->settings['imgdirs']['http://' . $info['host'] . '/'];
         if (!$IMG_DIR) {
             $IMG_DIR = IMG_DIR;
         }
         $filepath = $IMG_DIR . $info['dir'] . $info['filepath'] . $info['filename'] . ".json";
         $water_url = $position = "";
         if (file_exists($filepath)) {
             $json = json_decode(file_get_contents($filepath), true);
             //$water = $json['water'];   //原图加水印 缩略图不重复加水印
         }
         $path = $IMG_DIR . $info['dir'];
         $file = $path . $info['filepath'] . $info['filename'] . $info['type'];
         if (!file_exists($file) || !is_file($file)) {
             //文件不存在 显示默认图  font/indexbg.jpg
             //应用自定义默认图放在 font/{$app_uniqueid}/indexbg.jpg
             $default_img = CUR_CONF_PATH . 'font/indexbg.jpg';
             if (file_exists(CUR_CONF_PATH . 'font/' . $info['app_uniqueid'] . '/indexbg.jpg')) {
                 $default_img = CUR_CONF_PATH . 'font/' . $info['app_uniqueid'] . '/indexbg.jpg';
             }
             $this->readfile($default_img, 'indexbg.jpg');
         }
         $isSucc = hg_mk_images($file, $info['filename'] . $info['type'], $IMG_DIR . $info['dir'], $size, $water);
         if ($isSucc) {
             if (file_exists($filepath)) {
                 $thumb = json_decode(file_get_contents($filepath), true);
             } else {
                 $thumb = array();
             }
             $path = rtrim(realpath($path), '/') . '/';
             //记录绝对路径
             $thumb_tmp = $path . $size['label'] . "/" . $info['filepath'] . $info['filename'] . $info['type'];
             if (is_array($thumb['thumb']) && !in_array($thumb_tmp, $thumb['thumb']) || empty($thumb['thumb'])) {
                 // 判断这个列表不不存文件中
                 $thumb['thumb'][] = $thumb_tmp;
             }
             hg_file_write($filepath, json_encode($thumb));
             $header_url = 'http://' . $info['host'] . "/" . $info['dir'] . $size['label'] . "/" . $info['filepath'] . $info['filename'] . $info['type'];
             if ($this->settings['realtime_refresh_cdn'] && $this->settings['App_cdn']) {
                 include_once ROOT_PATH . 'lib/class/cdn.class.php';
                 $cdn = new cdn();
                 $cdn->push($header_url, '');
             }
             $file = $path . $size['label'] . "/" . $info['filepath'] . $info['filename'] . $info['type'];
             $this->readfile($file, $info['filename'] . $info['type'], $info['type']);
         } else {
             //缩略图创建失败  显示原图
             $this->readfile($file, $info['filename'] . $info['type']);
         }
     }
 }
Beispiel #2
0
 public function create_map_tuji()
 {
     if (empty($this->input['app_bundle']) || empty($this->input['module_bundle']) || empty($this->input['srcFile']) || empty($this->input['name'])) {
         $this->errorOutput('参数不完整');
     }
     $app_bundle = urldecode($this->input['app_bundle']);
     $module_bundle = urldecode($this->input['module_bundle']);
     $srcFile = explode(",", urldecode($this->input['srcFile']));
     $dstPath = hg_getimg_dir() . "material/sketch_map/" . $app_bundle . "/" . $module_bundle . "/";
     $name = urldecode($this->input['name']);
     $title = urldecode($this->input['title']);
     $pic_num = count($srcFile);
     $url = hg_getimg_host() . "material/sketch_map/" . $app_bundle . "/" . $module_bundle . "/" . $name;
     $save_file_path = $dstPath . $name;
     if ($this->check_file($save_file_path)) {
         $this->addItem($url);
         $this->output();
     } else {
         //示意图拷贝到背景上
         $tuji_map_bg = CUR_CONF_PATH . "font/tuji_map_bg.png";
         $tuji_map_bg_info = @getimagesize($tuji_map_bg);
         switch ($tuji_map_bg_info[2]) {
             case 3:
                 $bg = imagecreatefrompng($tuji_map_bg);
                 break;
             case 2:
                 $bg = imagecreatefromjpeg($tuji_map_bg);
                 break;
             case 1:
                 $bg = imagecreatefromgif($tuji_map_bg);
                 break;
             default:
                 return false;
         }
         imagealphablending($bg, false);
         imagesavealpha($bg, true);
         for ($i = 0; $i < 4; $i++) {
             if (empty($srcFile[$i])) {
                 continue;
             }
             $src = hg_getimg_dir() . app_to_dir($app_bundle) . $srcFile[$i];
             if (!file_exists($src)) {
                 continue;
             }
             //声称一张固定大小的图片
             $size = array('width' => 115, 'height' => 85);
             hg_mk_images($src, $name, $dstPath, $size, '', 20, 1);
             $img_info = getimagesize($save_file_path);
             switch ($img_info[2]) {
                 case 3:
                     $img = imagecreatefrompng($save_file_path);
                     break 1;
                 case 2:
                     $img = imagecreatefromjpeg($save_file_path);
                     break 1;
                 case 1:
                     $img = imagecreatefromgif($save_file_path);
                     break 1;
                 default:
                     return false;
             }
             imagecopy($bg, $img, 5 + 10 * ($i + 1) + 115 * $i, 45, 0, 0, $img_info[0], $img_info[1]);
         }
         $empty_img = imagecreatetruecolor($img_info[0], $img_info[1]);
         $white = imagecolorallocate($empty_img, 255, 255, 255);
         $gray = imagecolorallocate($empty_img, 192, 192, 192);
         imagefill($empty_img, 0, 0, $white);
         $str = "共{$pic_num}张图片";
         $rec = imagettfbbox(10, 0, '../font/simhei.ttf', $str);
         $w = $rec[2] - $rec[6];
         $h = $rec[3] - $rec[7];
         $x = ($img_info[0] - $w) / 2;
         $y = (85 - $h) / 2 + $h;
         imagettftext($empty_img, 10, 0, $x, $y, $gray, "../font/simhei.ttf", $str);
         $pic_num >= 4 ? $pic_num = 4 : $pic_num;
         imagecopy($bg, $empty_img, 5 + 10 * ($pic_num + 1) + 115 * $pic_num, 45, 0, 0, $img_info[0], $img_info[1]);
         //写标题
         $title = "图集:" . $title;
         $rect = imagettfbbox(12, 0, "../font/simhei.ttf", $title);
         $w = abs($rect[2] - $rect[6]);
         $h = abs($rect[3] - $rect[7]);
         $tmp_img = imagecreatetruecolor($w, $h);
         $white = imagecolorallocate($tmp_img, 255, 255, 255);
         imagefill($tmp_img, 0, 0, $white);
         imagecolortransparent($tmp_img, $white);
         $black = imagecolorallocate($bg, 0, 0, 0);
         imagettftext($tmp_img, 12, 0, 0, 12, $black, "../font/simhei.ttf", $title);
         imagecopymerge($bg, $tmp_img, 60, 18, 0, 0, $w, $h, 100);
         switch ($tuji_map_bg_info[2]) {
             case 3:
                 imagepng($bg, $save_file_path);
                 break;
             case 2:
                 imagejpeg($bg, $save_file_path);
                 break;
             case 1:
                 imagegif($bg, $save_file_path);
                 break;
             default:
                 return false;
         }
         $this->addItem($url);
         $this->output();
     }
 }
Beispiel #3
0
 public function createFile($water_id, $app_bundle, $filepath, $filename, $bs = "")
 {
     $imgdir = hg_getimg_dir($bs);
     $filepath = $imgdir . app_to_dir($app_bundle) . $filepath;
     $exttmp = explode('.', $filename);
     $json_file = $filepath . $exttmp[0] . '.json';
     $json = array();
     if (file_exists($json_file)) {
         $json = json_decode(file_get_contents($json_file), true);
     }
     $sql = "SELECT * FROM " . DB_PREFIX . "water_config WHERE id=" . $water_id;
     $ret = $this->db->query_first($sql);
     $json['water'] = array('type' => $ret['type'], 'filename' => $ret['filename'], 'opacity' => $ret['opacity'], 'position' => $ret['position'], 'water_text' => $ret['water_text'], 'water_font' => $ret['water_font'], 'font_size' => $ret['font_size'], 'water_color' => $ret['water_color'], 'water_angle' => $ret['water_angle'], 'margin_x' => $ret['margin_x'], 'margin_y' => $ret['margin_y'], 'condition_x' => $ret['condition_x'], 'condition_y' => $ret['condition_y']);
     hg_file_write($json_file, json_encode($json));
     copy($filepath . $filename, $filepath . 'nowater_' . $filename);
     include_once ROOT_PATH . 'lib/class/gdimage.php';
     $img = new GDImage();
     if ($json['water']['type'] == 1) {
         $json['water']['water_file_path'] = $json['water']['filename'] ? hg_getimg_default_dir() . WATER_PATH . $json['water']['filename'] : '';
         //根据图片大小和图片水印比例调整水印图片大小
         if ($this->settings['image_water_ratio'] && $json['water']['water_file_path']) {
             $img_info = getimagesize($filepath . $filename);
             $waterimg_info = getimagesize($json['water']['water_file_path']);
             if ($img_info[0] / $waterimg_info[0] < $this->settings['image_water_ratio']) {
                 $new_width = abs(intval($img_info[0] / $this->settings['image_water_ratio']));
                 hg_mk_images($json['water']['water_file_path'], $json['water']['filename'], hg_getimg_default_dir() . WATER_PATH . $new_width . '/', array('width' => $new_width, 'height' => ''), array());
                 $json['water']['water_file_path'] = hg_getimg_default_dir() . WATER_PATH . $new_width . '/' . $json['water']['filename'];
             }
         }
         $img->waterimg($filepath . $filename, $json['water']);
     } else {
         $json['water']['water_font'] = $json['water']['water_font'] ? CUR_CONF_PATH . 'font/' . $json['water']['water_font'] : CUR_CONF_PATH . 'font/arial.ttf';
         $json['water']['font_size'] = $json['water']['font_size'] ? $json['water']['font_size'] : 14;
         $img->waterstr($filepath . $filename, $json['water']);
     }
     return true;
 }