GD bounding box incorrect for text (php) -
i'm having issues text lining should. every tutorial can find tells me use imagettfbox find dimensions of text. this, text doesn't fit within dimensions.
see example below:
<?php // create image , colours $im = imagecreatetruecolor(200, 100); $white = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 0, 0, 0); $red = imagecolorallocate($im, 255, 0, 0); //set background white imagefilledrectangle($im, 0, 0, 200, 100, $white); //font file $font = "arial.ttf"; //set sample text , fontsize $text="102"; $size = 25; //calculate height , width of text1 $bbox = imagettfbbox($size, 0, $font, $text); $width = $bbox[2] - $bbox[0]; $height = $bbox[5] - $bbox[3]; //draw rectangle should house text imagefilledrectangle($im, 50, 40, 50+$width, 40+$height, $red); //draw text @ same startpoint rectangle imagettftext($im, $size, 0, 50, 40, $black, $font, $text); // output browser header('content-type: image/png'); imagepng($im); imagedestroy($im); ?>
this should output red rectangle, containing text. doesn't - text right of should be. happens strings - ones contain "1" tend not work, while others work perfectly. here output 2 strings:
does know happening, , need make text fit correctly within bounding box? i've tested multiple fonts, including monospace fonts - same thing happens.
Comments
Post a Comment