Home >Backend Development >PHP Tutorial >Create GIF using PHP_PHP tutorial
PHP can be used for more than just creating HTML output. It can also be used to create GIF graphic files and even create simpler GIF image streams. To do this, you will need to use the GD library to compile the PHP source files.
Example 2-2. Use PHP to create GIF files
Header("Content-type: image/gif");
$string=implode($argv," ") ;
$im = imagecreatefromgif("images/button1.gif");
$orange = ImageColorAllocate($im, 220, 210, 60);
$px = (imagesx($im)-7.5 *strlen($string))/2;
ImageString($im,3,$px,9,$string,$orange);
ImageGif($im);
ImageDestroy($im);
?>
This example will be called by a page using a method similar to: . The script about button.php3 will overlay this text on the basic graphic (in this case "images/button1.gif") and then output the resulting graphic. This is a very convenient way to prevent the button graphic from being redrawn every time the user wants to change the button's text. Using this approach, they will be used dynamically.