note 65251 added to function.imagettftext
| From: | jpetsel at riverviewtech dot net | Date: | Thu, 27 Apr 2006 19:06:01 +0000 |
| Subject: | note 65251 added to function.imagettftext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-109877@lists.php.net to get a copy of this message | ||
I was looking at ugo's center and it was great for left to right centering, but it
wouldn't center up and down. So with some changes to suit my needs this is what I came up
with. Some of the notations are just for my edifcation so may mean nothing for you all but you will
see I added a $posy that helps with centering up and down. I was also feeding my feilds from a
form.
<?php
// Set the content-type
header("Content-type: image/png");
//1line per column
$text=array(0=>$_POST['linei'],1=>$_POST['lineii'],
2=>$_POST['lineiii'],3=>$_POST['lineiv'],4=>$_POST['linev']);
$Image_Width=400;
$Text_Size=$_POST['textsize'];
$Image_Height=400;
// Create the image
$im = imagecreatetruecolor ($Image_Width, $Image_Height); /* Create a blank image */
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 1, 1, 398, 398, $white);
// Replace path by your own font path
$font = $_POST['font_name'];
for ($i=0; $i < sizeof($text); $i++) {
//Center the text
$Text_Box_Size = imagettfbbox($Text_Size, 0, $font, $text[$i]);
$Text_Box_Width = abs($Text_Box_Size[2] + $Text_Box_Size[0]);
$Text_Box_Height = abs($Text_Box_Size[7] + $Text_Box_Size[1]);
$Text_Height = $Text_Height + $Text_Box_Height;
$posx = ($Image_Width - $Text_Box_Width) / 2;
$posy = ($Image_Height - $Text_Box_Height * sizeof($text)) / 2 + $Text_Height;
/*
Add the text (***array imagettftext ( resource image, float size, float angle,
int x, int y, int color, string fontfile, string text )***)
*/
imagettftext($im, $Text_Size, 0, $posx, $posy, $black, $font, $text[$i]);
}
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
----
Server IP: 64.71.164.2
Probable Submitter: 208.47.119.115
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.imagettftext.php
Edit -- http://master.php.net/note/edit/65251
Del: integrated -- http://master.php.net/note/delete/65251/integrated
Del: useless -- http://master.php.net/note/delete/65251/useless
Del: bad code -- http://master.php.net/note/delete/65251/bad+code
Del: spam -- http://master.php.net/note/delete/65251/spam
Del: non-english -- http://master.php.net/note/delete/65251/non-english
Del: in docs -- http://master.php.net/note/delete/65251/in+docs
Del: other reasons-- http://master.php.net/note/delete/65251
Reject -- http://master.php.net/note/reject/65251
Search -- http://master.php.net/manage/user-notes.php