逐字书写....间距可调....通过$font_spacing调整
Code
1 <?php
2 // macleo 2008.9.20.Sat.
3 //逐字书写.间距可调.通过$font_spacing调整
4
5 //defined ttf location and text will display
6 $font_path = "font/";
7 $font_name = $font_path."fzhc_GBK.ttf";
8 $font_size = 50;
9 $font_angle = 0 ;
10 $text = array("逐","字","书","写","间","距","可","调");
11 $font_spacing = 25;//字间距调整设置
12 $picname = "CanAdjust";
13 $position_x = 50;//first Character coordinate x;
14 $position_y = 70;//first Character coordinate x;
15 $font_shade_spacing_x = 3;
16 $font_shade_spacing_y = 3;
17 $im = imagecreatetruecolor(800, 100);
18
19 // colors
20 $white = imagecolorallocate($im, 0xff, 0xff, 0xff);
21 $grey = imagecolorallocate($im, 0x98, 0x98, 0x98);
22 $black = imagecolorallocate($im, 0x00, 0x00, 0x00);
23
24 imagefilledrectangle($im, 0, 0, 800, 100, $white);
25 // line
26 imageline ( $im, 799, 0, 0, 0, $black );//top
27 imageline ( $im, 799, 99, 0, 99, $black );//bottom
28 imageline ( $im, 0, 99, 0, 0, $black );//left
29 imageline ( $im, 799, 99, 799, 0, $black );//right
30
31 // get weight of every character of Chinese
32 $font_coordinate = imagettfbbox ( $font_size, $font_angle, $font_name, $text[0] );
33 $font_weight = $font_coordinate[2] - $font_coordinate[0];
34 $font_height = abs($font_coordinate[5]) - $font_coordinate[3];
35
36 //output text from array
37 for($count = 0 ; $count<=count($text) ; $count++)
38 {
39 $arr = imagettftext($im, $font_size, $font_angle , $position_x , $position_y, $grey, $font_name, $text[$count]);
40 imagettftext($im, $font_size, $font_angle , $position_x-$font_shade_spacing_x , $position_y-$font_shade_spacing_y, $black, $font_name, $text[$count]);
41 $position_x = $position_x + $font_weight + $font_spacing;
42 }
43
44 header('Content-disposition: inline; filename='.$picname.'.png');
45 imagepng($im);
46 ImageDestroy($im);
47 ?>
1 <?php
2 // macleo 2008.9.20.Sat.
3 //逐字书写.间距可调.通过$font_spacing调整
4
5 //defined ttf location and text will display
6 $font_path = "font/";
7 $font_name = $font_path."fzhc_GBK.ttf";
8 $font_size = 50;
9 $font_angle = 0 ;
10 $text = array("逐","字","书","写","间","距","可","调");
11 $font_spacing = 25;//字间距调整设置
12 $picname = "CanAdjust";
13 $position_x = 50;//first Character coordinate x;
14 $position_y = 70;//first Character coordinate x;
15 $font_shade_spacing_x = 3;
16 $font_shade_spacing_y = 3;
17 $im = imagecreatetruecolor(800, 100);
18
19 // colors
20 $white = imagecolorallocate($im, 0xff, 0xff, 0xff);
21 $grey = imagecolorallocate($im, 0x98, 0x98, 0x98);
22 $black = imagecolorallocate($im, 0x00, 0x00, 0x00);
23
24 imagefilledrectangle($im, 0, 0, 800, 100, $white);
25 // line
26 imageline ( $im, 799, 0, 0, 0, $black );//top
27 imageline ( $im, 799, 99, 0, 99, $black );//bottom
28 imageline ( $im, 0, 99, 0, 0, $black );//left
29 imageline ( $im, 799, 99, 799, 0, $black );//right
30
31 // get weight of every character of Chinese
32 $font_coordinate = imagettfbbox ( $font_size, $font_angle, $font_name, $text[0] );
33 $font_weight = $font_coordinate[2] - $font_coordinate[0];
34 $font_height = abs($font_coordinate[5]) - $font_coordinate[3];
35
36 //output text from array
37 for($count = 0 ; $count<=count($text) ; $count++)
38 {
39 $arr = imagettftext($im, $font_size, $font_angle , $position_x , $position_y, $grey, $font_name, $text[$count]);
40 imagettftext($im, $font_size, $font_angle , $position_x-$font_shade_spacing_x , $position_y-$font_shade_spacing_y, $black, $font_name, $text[$count]);
41 $position_x = $position_x + $font_weight + $font_spacing;
42 }
43
44 header('Content-disposition: inline; filename='.$picname.'.png');
45 imagepng($im);
46 ImageDestroy($im);
47 ?>