Generate Button Image With Text Rendered On The Fly

Here is the content of the php file that will be served by as an image. The header function will inform the browser that it will receive a png image. The image will be available as http://mysitecom/button.php?text=Download

header("Content-type: image/png");

$text = $_GET['text'];
$image = imagecreatefrompng("images/background-button.png");
$color = imagecolorallocate($image, 255, 255, 255);

$px = ( imagesx ( $image ) - 7.5 * strlen( $string ) ) / 2;
$py = 9;

$fontSize = 1;

imagestring($image, fontSize, $px, $py, $text, $color);
imagepng($image);
imagedestroy($image);

Leave a Reply

Your email address will not be published. Required fields are marked *