array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'en', ), 'this' => array ( 0 => 'image.examples-png.php', 1 => 'PNG creation with PHP', ), 'up' => array ( 0 => 'image.examples.php', 1 => 'Examples', ), 'prev' => array ( 0 => 'image.examples.php', 1 => 'Examples', ), 'next' => array ( 0 => 'image.examples-watermark.php', 1 => 'Adding watermarks to images using alpha channels', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/image/examples.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
Example #1 PNG creation with PHP
<?php
header("Content-type: image/png");
$string = $_GET['text'];
$im = imagecreatefrompng("images/button1.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
?>
<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.