We have 28 guests online
   
PHP Scripts arrow Free PHP Tutorials arrow Free PHP Tutorials arrow PHP Tutorials and Examples arrow PHP 
Free PHP Tutorials arrow PHP Tutorials and Examples arrow PHP

PNG image creation - overlay text on an existing image
User Rating: / 17
PoorBest 

Creating a PNG with PHP. This could be expanded to create a security image for use in forms to check for robots. Just set $string to a randomly generated string. From php.net: "This example would be called from a page with a tag like: <img src="button.php?text=text">. The above button.php script then takes this "text" string and overlays it on top of a base image which in this case is "images/button1.png" and outputs the resulting image. This is a very convenient way to avoid having to draw new button images every time you want to change the text of a button. With this method they are dynamically generated." This script taken from the PHP manual (http://www.php.net/manual/en/ref.image.php).

  1. <?php
  2.  
  3. header("Content-type: image/png");
  4. $string = $_GET['text'];
  5. $im    = imagecreatefrompng("images/button1.png");
  6. $orange = imagecolorallocate($im, 220, 210, 60);
  7. $px    = (imagesx($im) - 7.5 * strlen($string)) / 2;
  8. imagestring($im, 3, $px, 9, $string, $orange);
  9. imagepng($im);
  10. imagedestroy($im);
  11.  
  12. ?> 

 

 

Directory Stats

There are 882 listing and 46 categories in our website

Change Language