景图 $bgimgdir = PLUGIN_PATH.'le_title_pic/bg_img/'; if( !is_dir($bgimgdir) ){exit();} $all_image_files = _scandir($bgimgdir);//背景图存放文件夹的jpg图片 foreach ($all_image_files as $k=>$file){ if($file == '.' || $file == '..'){ unset($all_image_files[$k]); } } if( empty($all_image_files) ){ exit(); } shuffle($all_image_files); $backgroundFile = array_slice($all_image_files, 0, 1); $backgroundPath = $bgimgdir.$backgroundFile[0]; $font = PLUGIN_PATH."le_title_pic/static/font.otf"; //字体 $size = 14; //默认字体大小 $oneline = 10; preg_match_all("/./u", $title, $t_arr);//将所有字符转成单个数组 $tarr = $t_arr[0]; $t_total = count($tarr); //标题长度 if($t_total > 30){ $t_total = 30; } $cha = 30 - $t_total; $size = $size + $cha; if($size > 28 ){ $size = 28; }elseif($size < 18){ $size = 18; } $text = ''; if($t_total > $oneline){ $line = 2; $bnum = $t_total/2; $snum = 0; for ($x = 0; $x < $t_total; $x++) { $snum++; if($snum >= $bnum){ $snum = 0; $text .= $tarr[$x].PHP_EOL; }else{ if($x > 27){ $text .= "..."; break; }else{ $text .= $tarr[$x]; } } } }else{ $text = $title; $line = 1; } //创建图片 $img = imagecreatefromjpeg($backgroundPath); $width = imagesx($img); $height = imagesy($img); if($line > 1){ $a = imagettfbbox($size, 0, $font, $text); //得到字符串虚拟方框四个点的坐标 $len = $a[2] - $a[0]; $x = ($width-$len)/2; $h = $size/10; $y = ($height/2)-15+$h; }else{ $a = imagettfbbox($size, 0, $font, $text); //得到字符串虚拟方框四个点的坐标 $len = $a[2] - $a[0]; $x = ($width-$len)/2; $h = $size/10; $y = ($height/2)+10+$h; } $color = imagecolorallocate($img, 255, 255, 255); // 0 0 0 表示黑色 $setting = $this->kv->get('le_title_pic_setting'); $cache_day = $setting['cache_day'].' day'; //缓存天数 //将规定当前页面缓存的时间(两天),并在下一次访问中使用这个缓存时间节点。接下来判断是否已经有缓存,如果有,就使用缓存。 header("Cache-Control: private, max-age=10800, pre-check=10800"); header("Pragma: private"); header("Expires: " . date(DATE_RFC822, strtotime($cache_day))); header("Content-type:image/jpeg"); imagettftext($img, $size, 0, $x, $y, $color, $font, $text); imagejpeg($img); imagedestroy($img); exit(); } // mz/ 路径解析 - 宝宝起名方案页 if(substr($uri , 0 , 4) == 'mz/' && strlen($uri) > 4){ $newurl = substr($uri, 0, -$url_suffix_len); $u_arr = explode('/', $newurl); if(!isset($u_arr[1])){ core::error404(); } $_GET['control'] = 'qm'; $_GET['action'] = 'mz'; $_GET['xing'] = $u_arr[1]; // 解析性别和类型 if(isset($u_arr[2])){ $sex_type = explode('_', $u_arr[2]); $_GET['sex'] = isset($sex_type[0]) ? $sex_type[0] : 0; $_GET['type'] = isset($sex_type[1]) ? $sex_type[1] : 1; } return; } // 笔画URL解析 - 移到最前面,确保最先被调用 $r = $this->bihua_url($cfg, $uri); if($r){return;} // 部首URL解析 $r = $this->bushou_url($cfg, $uri); if($r){return;} // Lecms 3.0.3 lang[error]

lang[error_info]

lang[error_line]

lang[basic_trace]

lang[program_flow]

SQL

$_GET

$_POST

$_COOKIE

lang[include_file]

lang[other_trace]