在写countpng时,对imagettfbox和imagettftext的一点见解,请各位大侠不吝赐教!本人原创文章!
| imagettfbbox与imagettftext函数的坐标系统认识 |
imagettfbbox函数的坐标系统的认识写 TTF 文字到图中。 语法: array ImageTTFBBox(int size, int angle, string fontfile, string text); 返回值: 数组 函数种类: 图形处理
本函数将 TTF (TrueType Fonts) 字型文字写入图片。参数 size 为字形的尺寸;angle 为字型的角度,顺时针计算,0 度为水平,也就是三点钟的方向 (由左到右),90 度则为由下到上的文字;x,y 二参数为文字的坐标值 (原点为左下角);参数 col 为字的颜色;fontfile 为字型文件名称,亦可是远端的文件;text 当然就是字符串内容了。返回值为数组,包括了八个元素,头二个分别为左下的 x、y 坐标,第三、四个为右下角的 x、y 坐标,第五、六及七、八二组分别为右上及左上的 x、y 坐标。治募注意的是欲使用本函数,系统要装妥 GD 及 Freetype 二个函数库。 使用范例 <?php //Header("Content-type:image/png"); //$im = imagecreate(400,30); //$black = ImageColorAllocate($im, 0,0,0); //$white = ImageColorAllocate($im, 255,255,255); $fontarea = ImageTTFBBox(20,0,"font/arial.ttf","I am NUMBER ONE !!");//返回值赋给$fontsize //$fontindex=sizeof($fontsize);//获得数组大小 //$string=NULL; while ( list( $key, $val ) = each( $fontarea ) ) { echo "$key => $val<br>"; } //ImageTTFText($im, 20, 0, 10, 24, $white, "font/arial.ttf", "I am NUMBER ONE !!"); //Imagepng($im); //ImageDestroy($im); //计算动态图象的高和宽 $font_width = $fontarea[2]-$fontarea[0];//256 $font_height = $fontarea[1]-$fontarea[7];//19 $images_width = $font_width+10;//定义生成计数器图象宽度 //$images_height=15;//定义生成计数器图象高度 $images_height = $font_height+10; $font_location_x =5; $font_location_y = ($images_height-$font_height)/2+$fontarea[7]; echo "images_width=$images_width<br>images_height=$images_height<br>"; echo "font_width=$font_width<br>font_height=$font_height<br>"; echo "font_location_x=$font_location_x<br>font_location_y=$font_location_y<br>"; ?> 使用范例的返回内容: 使用图像分析: 自己的分析:
2003.7.3. |