problems with gd vs gd2 on 4.3

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
mgm_03
Forum Newbie
Posts: 20
Joined: Thu Aug 07, 2003 3:49 pm

problems with gd vs gd2 on 4.3

Post by mgm_03 »

I am running Jaguar 10.2.6 and have installed PHP via the installer on entropy.ch. I've been coding successfully for a few months. I am using DWMX for color-coding . In my attempt to learn about creating thumbnail images, I have conflicting info.

phpinfo() gives me:

Configure command:

......'--with-gd' '--with-png-dir=/usr/local/php' '--with-freetype-dir=/usr/local/php' '--with-t1lib=/usr/local/php' '--with-jpeg-dir=/usr/local/php' '--with-tiff-dir=/usr/local/php' ....etc.

GD :
GD Support -- enabled
GD Version -- bundled (2.0.12 compatible)
FreeType Support --enabled
FreeType Linkage with freetype T1Lib Support --enabled
GIF Read Support -enabled
JPG Support --enabled
PNG Support --enabled
...etc...

I un-commented : "extension=php_gd2.dll" in the php.ini
I re-started Apache.

This sample script I pasted from the php manual (imagecreate function) works fine:

Code: Select all

<?php 
 header ("Content-type: image/png"); 
 $im = @imagecreate (50, 100) 
     or die ("Cannot Initialize new GD image stream"); 
 $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); 
 imagedestroy ($im); 
 ?>


I am unable to use the imagecreatetruecolor function which I understand is only on gd2 or later. I can't get imagecreate to work at all with jpg (not talking about quality of images, just functioning) ...I substituted jpg for png but no-go. In fact, DWMX highlighting indicates something wrong as soon as I try to change imagecreate to imagecreatetruecolor.

In the php manual, someone wrote a script to check which version of gd is installed...I ran it and it says "you have version less than 2"



Code:

Code: Select all

<?php 
 ob_start ();  
 phpinfo (8);  
 $phpinfo =ob_get_contents ();  
 ob_end_clean ();  
 $phpinfo =strip_tags ($phpinfo );  
 $phpinfo =stristr ($phpinfo ,"gd version" );  
 $phpinfo =stristr ($phpinfo ,"version" );  
 $end =strpos ($phpinfo ," " );  
 $phpinfo =substr ($phpinfo ,0,$end );  
 $phpinfo =substr ($phpinfo ,7);  
 if( version_compare ("2.0" ,"$phpinfo" )== 1) 
 echo "you have a version less then 2" ; 
 ?>


I appears I don't have gd2. My project involves taking user uploaded jpegs and storing them for an online directory. If there's no way to control what version of gd is used by the hosting company I select, then, I am stuck with using imagecreate (not-preferred). I tried using a jpg image on my system but that doesn't work. I get a parse error on the line corresponding to header ("content-type: image/jpg").

sorry for the long post. I presume more detail is better than less. I'm a newbie so pardon if I am missing something obvious.

THANKS in ADVANCE.

Back to top
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

if your phpinfo() returns the text you listed then GD2.0.12 is up and operational -

the php manual test for gd2 is very dodgy and all it would do is check the forst seven chars of the version line of phpinfo which in your case would be bundled (......) - as it looks for 2.0 it wouldn't find it and therefore says 'version below 2' wrongly.

a better test is simply to run

var_dump(gd_info());

if that works, you have GD2+

a note though: version 2.0.12 (maybe 2.0.10 to 2.0.14 - certainly PHP 4.3.2 bundled version) has a known bug in the imagecopymerge function. fixed in 2.0.15
mgm_03
Forum Newbie
Posts: 20
Joined: Thu Aug 07, 2003 3:49 pm

Post by mgm_03 »

Thanks for replying with help.

var_dump(gd_info()); gives me:

Code: Select all

array(11) &#123;   &#1111;"GD Version"]=>   string(27) "bundled (2.0.12 compatible)"   &#1111;"FreeType Support"]=>   bool(true)   &#1111;"FreeType Linkage"]=>   string(13) "with freetype"   &#1111;"T1Lib Support"]=>   bool(true)   &#1111;"GIF Read Support"]=>   bool(true)   &#1111;"GIF Create Support"]=>   bool(false)   &#1111;"JPG Support"]=>   bool(true)   &#1111;"PNG Support"]=>   bool(true)   &#1111;"WBMP Support"]=>   bool(true)   &#1111;"XBM Support"]=>   bool(true)   &#1111;"JIS-mapped Japanese Font Support"]=>   bool(false) &#125;
What baffles me is this..... DWMX highlights functions in blue as you type in the coding. So, when I type the word "imagecreate", upon reaching the last letter ("e"), DWMX switches the color of the word from black to blue. this means it is valid. It's a nice debugging feature. It works for functions like "print", "header", etc. Now, as it relates to GD,

A: It works for:
imagecreate, imagecopyresized, imagepng, getimagesize, imagecolorallocate, imagecreatefrompng

B: It does not work for:
imagecreatetruecolor, imagejpg, imagecopyresampled, imagecreatefromjpg

Code: Select all

<?php
imagecreate(); //works
imagecreatefrompng(); //works
imagecreatefromjpg(); //doesn't work
?>
Any small bits of code I have used to test GD ran properly using group A but not group B. I don't know if this is an issue with Mac OS 10.2. if it was I would've expected many others to have the same prob and I have searched everywhere and this is really unfamiliar waters
Post Reply