Posted By

mikeejay on 10/25/06


Tagged

image gd text graphic


Versions (?)

Who likes this?

29 people have marked this snippet as a favorite

yuconner
visualAesthetic
blakeb
vali29
hudge
willcodeforfood
benrasmusen
motoroller
skywalker
cristianciofu
SpinZ
llexa
jamesming
irishsk
nb109
kellyrmartin
Adam42
heatherk
osirisinternet
all3n
dinkan
mecha
michellebracken
prit
uberdragon
wirenaught
hypertext03
Some0ne
tux-world


text2image


 / Published in: PHP
 

Put contents in a file called for example "button.php". instead of using filename.png in the img tag, use button.php?text=buttontext

  1. header("Content-type: image/png");
  2. $string = $_GET['text'];
  3. $im = imagecreatefrompng("images/button.png");
  4. $color = imagecolorallocate($im, 255, 255, 255);
  5. $px = (imagesx($im) - 7.5 * strlen($string)) / 2;
  6. $py = 9;
  7. $fontSize = 1;
  8.  
  9. imagestring($im, fontSize, $px, $py, $string, $color);
  10. imagepng($im);
  11. imagedestroy($im);

Report this snippet  

You need to login to post a comment.