Re: Button Creation Backfiring

From: Date: Fri, 09 May 2003 09:07:09 +0000
Subject: Re: Button Creation Backfiring
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-146985@lists.php.net to get a copy of this message
it is a typo or you should put a ';' at the end of line 61 ??? ----- Original Message ----- From: "Chris Blake" <cblake@pbpc.co.za> To: "Php-General" <php-general@lists.php.net> Sent: Friday, May 09, 2003 12:00 PM Subject: [PHP] Button Creation Backfiring > Greetings learned PHP(eople) > > Objective : Create some buttons > Code : > ----------------------------------------------------- > <?php > > //Posted from previous page > //Button text and colour > > $button_text = $HTTP_POST_VARS['button_text']; > $colour = $HTTP_POST_VARS['colour']; > > if (empty($button_text) || empty($colour)) > { > echo 'Could not create button'; > exit; > } > > //Create image from existing image > $image = imagecreatefrompng ($colour . '-button.png'); > > $image_width = ImageSX($image); > $image_height = ImageSY($image); > > //Image needs 18 pixel margin in from the edge image (?) > $image_width_wo_margins = $image_width - (2 * 18); > $image_height_wo_margins = $image_height - (2 * 18); > > //Work out if the font size will fit and make it > //smaller until it does. Start with large size and scale down > $font_size = 33; > > ********************************************* > ********************************************* > //Let GD2 know where fonts reside > //putenv('GDFONTPATH = ?'); > ********************************************* > ********************************************* > $fontname = 'arial'; > > do > { > $font_size--; > //Find out the size of the text at that font size > $bbox = imagettfbbox ($font_size, 0, $fontname, $button_text); > > $right_text = $bbox[2]; //Right co-ordinate > $left_text = $bbox[0]; //Left co-ordinate > $width_text = $right_text - $left_text; //How wide is it ? > $height_text = abs($bbox[7] - $bbox[1]); //How tall is it ? > } > > while ($font_size > 8 && > ($height_text > $image_height_wo_margins || $width_text > > $image_width_wo_margins) > ); > > if ($height_text > $image_height_wo_margins || $width_text > > $image_width_wo_margins) > { > //No readable font size will fit on button > echo 'Text given is too large for button'; > } > else > { > //The font size fits > //Now where to put it > $text_x = $image_width/2.0 - $width_text/2.0; > $text_y = $image_height/2.0 - $height_text/2.0 > > > ******THIS IS LINE 62******************** > ***************************************** > if ($left_text < 0 ) > ***************************************** > ***************************************** > { > $text_x += abs($left_text); //Factor for left overhang > $above_line_text = abs($bbox[7]); //How far above the baseline > $text_y += $above_line_text; //Add baseline factor > > $text_y -= 2; //Adjustment factor for shape of our template > $white = ImageColorAllocate($image, 255,255,255); > ImageTTFText ($image, $font_size, 0, $text_x, $text_y, $white, > $fontname, $button_text); > > Header('Content-type: image/png'); > ImagePng($image); > } > > ImageDestroy($image); > ?> > ---------------------------------------------------------------- > Problem : Parse error: parse error in > /home/data/ClientWebs/chrisplay/Generic/make_buttons.php on line 62 > > > Any ideas ? > And secondly : Where do fonts reside. I`m using Mandrake 9 and a search > for fonts brought up a fonts folder, with a file containing only a zero > byte file... > > Any help much appreciated. > Cheers > > -- > Chris Blake > Office : (011) 782-0840 > Cell : 083 985 0379 > "Remember, Information is not knowledge; Knowledge is not Wisdom; > Wisdom is not truth; Truth is not beauty; Beauty is not love; > Love is not music; Music is the best." -- Frank Zappa > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#146985) next »