Monday, March 20, 2006

Hard Earned Learnings

My Tough Time Learnings

I mention these Learnings are as tough time because I have really spent a lot of time in debugging these issues. This blog will be a mix-up of all the learning’s in various technologies. I start with PHP.

Configuring GD(Graphics Draw) for PHP

This write up guides you in installing and Configuring GD for PHP running as a Module in Apache for windows. The fact that I was using WAMP stack from Spike source took me some more time to identify the issue.

  • Get php_gd2.dll for windows – download php-5.1.2 binary from php.org. The distribution will contain a folder called “ext” which includes all the dlls. Copy this folder and paste it in your current php folder. For a WAMP stack it will be “C:\SpikeSource\oss\php5”. Also copy the dlls directly inside php-5.1.2-Win32 folder of the distribution and place it inside “C:\SpikeSource\oss\php5”. Now you have got all the dlls required for GD usage.
  • Configure php.ini – You have to tell PHP to load the GD extension for usage. For WAMP stack the php.ini file is under “c:\windows” directory. Don’t be taken away by the php.ini file in C:\SpikeSource\oss\php5 directory. This is just a copy. Open the php.ini file under c:\windows. Update the location of the extension folder.

; Directory in which the loadable extensions (modules) reside.

extension_dir = "C:/SpikeSource/oss/php5/ext"

Update the extension to be used. Remove the semi-colon from the line ;extension=php_gd2.dll

;Windows Extensions

;Note that ODBC support is built in, so no dll is needed for it.

extension=php_gd2.dll

  • Restart your Apache server. Now you are ready to use GD, great.
  • If you receive any errors in startup like - PHP Warning: PHP Startup: Unable to load dynamic library 'C:/SpikeSource/oss/php5/ext\php_gd2.dll' - The specified procedure could not be found. – then you haven’t copied the dlls completely.
  • Try the following program

header ("Content-type: image/png");

$img_handle = ImageCreate (230, 20) or die ("Cannot Create image");

$back_color = ImageColorAllocate ($img_handle, 0, 10, 10);

$txt_color = ImageColorAllocate ($img_handle, 233, 114, 191);

ImageString ($img_handle, 31, 5, 5, "My first Program with GD", $txt_color);

ImagePng ($img_handle);

?>

It should display a image for you. For further doubts contact me at prathapnirmal+gd@gmail.com.

No comments: