1. Computing & Technology

Discuss in my forum

GD Library - The Basics of Drawing with PHP

By , About.com Guide

7 of 7

Wraping Up the Basics
 <?php 
 header ("Content-type: image/gif"); 
 $handle = ImageCreate (130, 50) or die ("Cannot Create image"); 
 $bg_color = ImageColorAllocate ($handle, 255, 0, 0); 
 $txt_color = ImageColorAllocate ($handle, 0, 0, 0); 
 ImageString ($handle, 5, 5, 18, "PHP.About.com", $txt_color); 
 ImageGif ($handle); 
 ?> 
So far all of the images we have created have been PNG format. Above, we are creating a GIF using the ImageGif () function. We also change are headers accordingly. You can also use ImageJpeg () to create a JPG, as long as the headers change to reflect it appropriately.

You can call the php file just like you would a normal graphic. For example:

 <img src="http://www.yoursite.com/YourScript.php"> 

©2012 About.com. All rights reserved.

A part of The New York Times Company.