1. Home
  2. Computing & Technology
  3. PHP / MySQL

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">
Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Graphics- GD Library
  5. GD Library - PHP GD Library - GD Image Library

©2009 About.com, a part of The New York Times Company.

All rights reserved.