Get font height and width in PHP
Description
The following code shows how to get font height and width.
Example
<html>/*from www . j a v a 2s . c om*/
<body>
<?php
$img=ImageCreate(300,300);
$bgcolor=ImageColorAllocate($img,200,200,200);
$red=ImagecolorAllocate($img,255,0,0);
$green=ImagecolorAllocate($img,0,255,0);
$blue=ImagecolorAllocate($img,0,0,255);
$grey=ImagecolorAllocate($img,50,50,50);
$black=ImagecolorAllocate($img,0,0,0);
for($i=0;$i<10;$i++) {
ImageChar($img,$i,20,20+($i*20),"S",$red);
$height[]=Imagefontheight($i);
$width[]=Imagefontwidth($i);
}
/*
RGB Red = 0..255 , Green = 0..255 , Blue = 0..255.
*/
ImageSetPixel($img,50,50,$pixelcolor);
ImagePNG($img,"test.png");
ImageDestroy($img);
for ($i=0;$i<10;$i++) {
echo "font ".$i." height=".$height[$i]."<br>";
}
?>
<img src="pic.png" border=0>
</body>
</html>