PHP PNG image creation

Dismounted

59.***.***.***
1,958 days ago

PHP PNG image creation

PNG creation with dynamic text, in PHP with GD

Save this code as a .php file;

PHP code:

<?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);

?>



You can call this PHP script from a page with a normal image tag, like this one: <img src="filename.php?text=text" />. The script will then take the "text" string input and overlay it on top of a base image (which in this case is "images/button1.png"), before outputting the result as a valid PNG image.