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

GD Library - The Basics of Drawing with PHP

By Angela Bradley, About.com

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">

Index: GD Library - The Basics of Drawing with PHP

  1. What is the GD Library?
  2. Rectangle With Text
  3. Playing with Fonts
  4. Drawing Lines
  5. Drawing An Ellipse
  6. Arcs & Pies
  7. Wraping Up the Basics

7 of 7

Explore PHP / MySQL

More from About.com

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

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

All rights reserved.