using graphics in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jamal
Forum Commoner
Posts: 57
Joined: Sat Oct 26, 2002 7:53 pm
Location: London

using graphics in php

Post by jamal »

Hi Guys,
I am trying to check if GD-library is working together with PHP but it failed. I have to run the below code to check it. I have already downloaded GD-1.8.4.
Please can anyone help me on how to configure graphics with php.

Code: Select all

header ("Content-type: image/png"); 
$im = @ImageCreate ( 50, 100) 
    or die ("Cannot create a new GD image."); 
$background_color  = ImageColorAllocate  ($im, 255,  255, 255); 
$text_color  = ImageColorAllocate  ($im, 233,  14, 91); 
ImageString  ($im, 1,  5, 5,  "A Simple Text String", $text_color ); 
ImagePng  ($im);
thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

which version of php, which webserver, which OS and failed in what way? (because it's somehow working on my box ;) )
jamal
Forum Commoner
Posts: 57
Joined: Sat Oct 26, 2002 7:53 pm
Location: London

Post by jamal »

php version 4.2.4-dev
apache 1.3.26
win98
The failure is that I did not see the
logo.
Thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try this order

Code: Select all

$im = @ImageCreate ( 50, 100) 
    or die ("Cannot create a new GD image."); 
$background_color  = ImageColorAllocate  ($im, 255,  255, 255); 
$text_color  = ImageColorAllocate  ($im, 233,  14, 91); 
ImageString  ($im, 1,  5, 5,  "A Simple Text String", $text_color ); 
header ("Content-type: image/png"); 
ImagePng  ($im);
so you can see errors because Content-type isn't altered until the last statement. And take a look into server's error.log
jamal
Forum Commoner
Posts: 57
Joined: Sat Oct 26, 2002 7:53 pm
Location: London

Post by jamal »

I tried the code above but unfortunately I saw nothing. The page was blank.
Can you help me any futher. I checked the phpinfo to see if the gd was installed. I did not see it there. I am going crazy. I am interested in this concept. Can anybody help me anybody before I die?
Thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

the output of

Code: Select all

<?php phpinfo(); ?>
should contain a section simliar to
gd
GD Support enabled
GD Version 1.6.2 or higher
FreeType Support enabled
FreeType Linkage with TTF library
JPG Support enabled
PNG Support enabled
WBMP Support enabled
if not you have to add the php-gd extension.
  • In your php/extensions-directory there are two libs
  • php_gd.dll
  • php_gd2.dll
  • check your php.ini settings
  • extension_dir should point to your php/extensions-dir (e.g. mine is extension_dir = c:/programme/php423/extensions)
  • uncomment one extension-entry, either extension=php_gd.dll or extension=php_gd2.dll
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you used the PHP installer to install PHP then you won't have the extensions folder with all the nice useful extensions in it - you'll need the PHP zip package to get them.
http://www.php.net/downloads.php

Mac
jamal
Forum Commoner
Posts: 57
Joined: Sat Oct 26, 2002 7:53 pm
Location: London

using graphics in php

Post by jamal »

Yes I have reinstalled the php-4.2.3-win32 from the start again. I could see that it contained all the dlls. But I thought I have to install the gd at this site http://www.boutell.com/gd/manual1.8.4.html#whatis
before i can have it working??
Are these( gd, libpng, t1lib, freetype, and jpeg ) installed by default. The dlls are in the php in which I installed.
Thank you for sparing your time to assist me.
Jamal
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

the php_XYZ.dlls from the win32-zip-package are all you need, but you have to include these extensions in the php.ini
they are not loaded by default.
change

Code: Select all

;extension=php_XYZ.dll
to

Code: Select all

extension=php_XYZ.dll
to enable the extension.
Post Reply