-
error_reporting(7);
- define('ROOT', getcwd());
- define('BASEDIR', parse_url($ _VERVER ) ['REQUEST_URI'], PHP_URL_PATH));
- if ($_POST['text']) {
- $ret = array();
- $text = $_POST['text'];
- 嘗試{
- $ret['imgurl'] = text2img($text, (array) $_REQUEST['config']);
- }
- catch (異常$e) {
- $ ret ['imgurl'] = print_r($e, true);
- }
- echo str_replace('\/', '/', json_encode($ret));
- exit(0);
- }
- 函數text2img($text, $options = array())
- {
- $text .= "n------------------ -------------- - ------------n";
- $text .= "http://iscup.com";
- $rows = substr_count($text, "n") 1;
- $font_path = $options['fontfile'] ? $options['fontfile'] :根。 " 找不到字體檔案:$font_path ");
- $font_size = $options['fontsize' ]? $options['fontsize'] : 12;
- $padding = $options['padding'] ? $options['padding'] : 30;
- $row_plus_height = $options['row_plus_height'] ? $options['row_plus_height'] : 4;
- $border = 1;
- $im_width = 430;
- $im_height = ($row_plus_height ($font_size * 4) / 3) * $rows ($row_plus_height ($font_size * 4) / 3) * $ $border) * 2;
- $im = @imagecreatetruecolor($im_width, $im_height);
- if (!$im)
- throw new Exception("初始化圖片失敗,請檢查GD配置");
- imagefilledrectangle($im, $border, $border, ($im_width - 2 * $border), ($im_height - 2 * $border), imagecolorallocate($im, 255, 255, 255));
- imagettftext($im, $font_size, 0, ($border $padding), (($font_size * 4) / 3 $border $padding), imagecolorallocate($im, 0, 0, 0), $font_path, $text) ;
- $base_path = '/files';
- $base_filename = date("Y-m-d,H-i-s") . '.png';
- $short_filename = $base_path . '/' 。 $short_filename;
- @mkdir(ROOT . $base_path, 0777, true);
- $filename = ROOT . $short_filename;
- if (!imagepng($im, $filename)) {
- throw new Exception("建立圖片時發生錯誤。");
- }
- @imagedestroy($im);
- return $short_url;
- }
-
- ?>
-
- < >
- 長微博工具
-
-
-
長微博工具
-
長微博
-
-
|