Dynamically return an image in PHP

Create a page called image.php and paste the following code into it:

<?
// create an image with width 100px, height 20px
$image = imagecreate(100, 20);
// create a red colour for the background
// as it is the first call to imagecolorallocate(), this fills the background automatically
$red_background = imagecolorallocate($image, 255, 0, 0);
// create a black colour for writing on the image
$black = imagecolorallocate($image, 0, 0, 0);
// write the string "Hyve test" on the image
// the top left of the text is at the position (10, 2)
imagestring($image, 4, 10, 2,' hyve test', $black);
// output the image
// tell the browser what we.re sending it
Header('Content-type: image/png');
// output the image as a png
imagepng($image);
// tidy up
imagedestroy($image);
?>

Create a page called image.html and paste the following code into it:


<img src="http://www.domain.com/image.php"/>

Surf to the html page and you will see that the image appears.

Back to PHP

All Pages

Email

ASP

JSP

C#

Web Mail

Windows Plesk

Linux Plesk

PHP

ASP.NET

Persits ASPUpload

Wiki Help

  Page Info My Prefs Log in
This page (revision-2) last changed on 15:00 24-Apr-2007 by Administrator.
 
Page Hit Count: 29

Referring Pages:
...nobody

JSPWiki v2.4.71