Web Programming > PHP & Perl

Create image in runtime PHP: imagegif()

(1/1)

admin:
Sometimes we need to create an image in runtime without saving, just to display text or numbers that is usually used in the human verification.
it's very easy to use the following code and save it in a php file, say "image.php" then you can use this file as an image in your HTML code.


--- Code: ---<?php

// Create a new image instance
$im = imagecreatetruecolor(100, 100);

// Make the background white
imagefilledrectangle($im, 0, 0, 99, 99, 0xFFFFFF);

// Draw a text string on the image
imagestring($im, 3, 40, 20, 'GD Library', 0xFFBA00);

// Output the image to browser
header('Content-type: image/gif');

imagegif($im);
imagedestroy($im);

?>
--- End code ---

Navigation

[0] Message Index

Go to full version