Promo Offers XMAS Offers:
KVM VPS @ UP TO 50% OFF for 3 mos. Learn More Dedicated @ UP TO 56% OFF for 1 mo. Learn More
  • Your Cart is Empty
  • Cart
  • Log In

GD library

In today's image-heavy world, it's necessary to have a server side technology, which allows you to easily handle and even create images, charts, etc. And to satisfy this need, C developer Thomas Boutell created the GD library. It was quickly adopted by all the popular programming languages and especially PHP, for which a special modified version is created, and which provides additional features.

GD library

GD is an open source code library, which allows the user to dynamically create and edit images via a command line interface. The GD library has similar functionality as that of ImageMagick and offers "wrappers" for Perl, PHP and other languages. With it users can create PNG, JPEG and GIF images, as well as images in other formats. Most often the GD library is used to generate charts, thumbnails, graphics, etc.

GD Library usage

GD is often used in various web applications. Integrated in the latest PHP version- PHP5, GD not only expands the potentialities of PHP as far as the creation of HTML output is concerned, but also enables the users to create and manipulate images in different formats, including GIF, PNG, JPG, WBMP and XPM. Moreover, thanks to the GD library, PHP can output image streams directly to a browser.

Write text on a generated image:

<?php

// Set the content-type
header('Content-type: image/png');

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'My text here...';
// Replace path by your own font path
$font = './arialbd.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

imagepng($im);
imagedestroy($im);

?>

Check a file's image size:

<?php
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "<img src=\"img/flag.jpg\" $attr alt=\"getimagesize() example\" />";
?>

How to check if GD library is present on the server

You can easily check which GD library version your server is running with the help of a phpinfo.php file. If your host does not offer a ready phpinfo file, you can easily create it yourself - simply make an empty file, named "phpinfo.php" with the following code in it:

<?php
phpinfo();

And then open the file with your favorite web browser. In the output, look for the GD section, it should look like this:

GD Library

GD libraries and NTC Hosting

NTC Hosting offers its clients a PHP-optimized hosting service of the highest quality. Our PHP4and PHP5 versions are compiled with GD library support, which renders the installation of popular applications such as Coppermine, Joomla and Gallery2 a lot easier. You can check the current version of the GD libraries by using the Server Information section in your web hosting account's Control Panel.