note 27850 deleted from function.imagettfbbox by sniper

From: Date: Fri, 07 Nov 2003 12:41:00 +0000
Subject: note 27850 deleted from function.imagettfbbox by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-60081@lists.php.net to get a copy of this message
Note Submitter: skhanna@csc.tntech.edu ---- It took me a while to figure out what was going on with the bounding box. The hardest part is basically getting the width and height for your entire string rendered in a given font: $bbox = Imagettfbbox($fontsize,0,$font,$string) ; $width = ( ($bbox[0] > 0 && $bbox[2] > 0) || ($bbox[0] < 0 && $bbox[2] < 0) ) ? abs($bbox[2] - $bbox[0]) : ( abs($bbox[2]) + abs($bbox[0]) + 1 ); $height = ( ($bbox[1] > 0 && $bbox[5] > 0) || ($bbox[1] < 0 && $bbox[5] < 0) ) ? abs($bbox[1] - $bbox[5]) : ( abs($bbox[1]) + abs($bbox[5]) + 1 ); The trick is that some text will render totally above the horizontal axis, some will render totally bellow it and some will render on both sides of it (same with the vertical axis). The two functions listed above will give you the width and height in every possibly case (given that your angle is set to 0). After that, finding the lower left corner to draw your text to an image using the ImageTTFText() is as simple as: $X = (imagesx($image)-$width)/2; $Y = ((imagesy($image)-$height)/2)+$height;

« previous php.notes (#60081) next »