Jump to content


Photo

Image Generation


  • Please log in to reply
4 replies to this topic

#1 Gobiggi

Gobiggi
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 15 August 2006 - 10:42 PM

k ive been looking for help in loads of places, and got some of it, so ive got this far but my script still doesn't work, all i get is a red X,
what i am aiming for is to create images like this:
Posted Image
but what i need is the last pixel of the last word staying in the same place for every text that is entered, so far my script is:
<?php 
   header("Content-type: image/png"); 
   $string = urldecode($_GET['text']); 
   $im = imagecreatefrompng("template.png"); 
   $fontsize = 10; 
   $fontsize2 = 12; 
   $angle = 25; 
   $font = "visitor1.ttf"; 
   $textColor = imagecolorallocate($im,255,255,255) 
   $textColor2 = imagecolorallocate($im,0,0,0); 
   array imagettfbbox(12,25,$font,$string); 
   imagettftext($im, $fontSize2, 25, 291, -1, $textColor2, $font, $string); 
   imagettftext($im, $fontSize, 25, 290, 0, $textColor, $font, $string); 
   imagepng($im); 
   imagedestroy($im); 
?> 
but i really think ive made loads of mistakes that i cannot find,
please help me do this.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 15 August 2006 - 11:08 PM

try
<?php 
   header("Content-type: image/png"); 
   $string = urldecode($_GET['text']); 
   $im = imagecreatefrompng("template.png");
   $height = imagesy($im);
   $width = imagesx($im); 
   $fontsize = 10; 
   $fontsize2 = 12; 
   $angle = 25; 
   $font = "visitor1.ttf"; 
   $textColor = imagecolorallocate($im,255,255,255); 
   $textColor2 = imagecolorallocate($im,0,0,0); 
   $array  = imagettfbbox($fontsize2,$angle,$font,$string);
   $ypos = $height - 5; // baseline of text
   $xendpos = $width-10; // text ends 10px from right
   $textwidth = $array[2] - $array[0];
   $xpos = $xendpos - $textwidth;
   imagettftext($im, $fontSize2, $angle, $xpos+1, $ypos-1, $textColor2, $font, $string); 
   imagettftext($im, $fontSize, $angle, $xpos, $ypos, $textColor, $font, $string); 
   imagepng($im); 
   imagedestroy($im); 
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Gobiggi

Gobiggi
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 15 August 2006 - 11:49 PM

Wow! Thanks man,
but i still have one problem, when i type:
img.php?text=Gobiggi
no text appears

but thanks for the above text, and hopefully you can help me overcome this problem, because im a total php noob,

#4 Gobiggi

Gobiggi
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 16 August 2006 - 12:45 AM

c'mon nearly an hour and no replies, i really want to get this script done so i can get it out of the way

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 18 August 2006 - 12:31 AM

Works better if both fontsizes are the same

<?php 
   header("Content-type: image/png"); 
   $string = urldecode($_GET['text']);
   $im = imagecreate(100, 120);  // as I don't have your template image'
   $height = imagesy($im);
   $width = imagesx($im); 
   $fontsize = 12; 
   $fontsize2 = 12; 
   $angle = 25; 
   $font = "c:/windows/fonts/arialbd.ttf";     // used a font on my pc here
   $bg = imagecolorallocate($im, 228,228,228); 
   $textColor = imagecolorallocate($im,255,255,255); 
   $textColor2 = imagecolorallocate($im,0,0,0); 
   $array  = imagettfbbox($fontsize2,$angle,$font,$string);
   $ypos = $height - 50; // baseline of text
   $xendpos = $width-10; // text ends 10px from right
   $textwidth = $array[2] - $array[0];
   $xpos = $xendpos - $textwidth;
   imagettftext($im, $fontsize2, $angle, $xpos+1, $ypos-1, $textColor2, $font, $string); 
   imagettftext($im, $fontsize, $angle, $xpos, $ypos, $textColor, $font, $string); 
   imagepng($im); 
   imagedestroy($im); 
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users