ali_2kool2002 Posted March 31, 2007 Share Posted March 31, 2007 does anyone know how to configure GD Library in simple instructions for making bar graphs? please help if you can... im using windows xp with php apache macromedia dreamweaver Quote Link to comment Share on other sites More sharing options...
Barand Posted March 31, 2007 Share Posted March 31, 2007 1 ) Have you now downloaded the php_gd2.dll file from php.net? 2 ) Have you looked in you php.ini file for the line extension_dir = xxxx 3 ) Have you put the .dll file in the folder xxxx as defined in the ini file. 4 ) Have you then looked in the php.ini file for the line ;extension=php_gd2.dll and removed the ; from the beginning. When you have, let us know. I know this may sound familiar as I answered this here http://www.phpfreaks.com/forums/index.php/topic,133944.msg563734.html#msg563734 Quote Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted April 1, 2007 Author Share Posted April 1, 2007 i have downloaded the gd2.035rc1 which is one of their latest library, but iv looked inside the folder and cant find a dll file? im using php 5.1.4 if that helps? thanks for your other reply, is more straight forward Quote Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted April 1, 2007 Author Share Posted April 1, 2007 every time i look for a library on php.net it says its moved to another link and when i click the link it goes to http://www.libgd.org/Main_Page.. this is where i dowloaded the file gd-2.0.35RC1.tar.bz2 which has no dll file.. any further ideas ?thanks another good site is http://www.maani.us/charts/index.php but the chart doesnt change when i follow its tutorial, is this because it requires GD aswel? Quote Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted April 1, 2007 Author Share Posted April 1, 2007 hi iv made some kind of progress as the error of not recognising the image create has gone... however, i have a error on your script for bar.php its Notice: Undefined index: val in h:\Project\htdocs\fiinalyear\charts\bar.php on line 23 Notice: Undefined index: max in h:\Project\htdocs\fiinalyear\charts\bar.php on line 24 ‰PNG IHDRf íÞ Í PLTEàààÿ‡½ß°IDATxœcÅp‘(…; úÙ[Fã\IEND®B`‚ Quote Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted April 1, 2007 Author Share Posted April 1, 2007 bar.php is on this site below: http://www.phpfreaks.com/forums/index.php/topic,133944.msg563734.html#msg563734 Quote Link to comment Share on other sites More sharing options...
Barand Posted April 1, 2007 Share Posted April 1, 2007 This version should stop those notices when no values are passed to the script. <?php // set dimensions $w = 102; $h = 12; // create image $im = imagecreate($w, $h); // set colours to be used $bg = imagecolorallocate($im, 0xE0, 0xE0, 0xE0); $black = imagecolorallocate($im, 0x00, 0x00, 0x00); $barcolor = imagecolorallocate($im, 0xFF, 0x00, 0x00); // draw border imagerectangle($im, 0,0,$w-1,$h-1,$black); // get value and max value from query string $val = isset($_GET['val']) ? $_GET['val'] : 0; $max = isset($_GET['max']) ? $_GET['max'] : 100; // calculate dimensions of inner bar $barw = $max ? floor(($w-2) * $val / $max) : 0; $barh = $h - 2; // draw inner bar if ($barw) imagefilledrectangle($im, 1, 1, $barw, $barh, $barcolor); // send image header header("content-type: image/png"); // send png image imagepng($im); imagedestroy($im); ?> Quote Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted April 1, 2007 Author Share Posted April 1, 2007 the notices have gone but all i get if i go onto bar.php is : ‰PNG IHDRf íÞ Í PLTEàààÿ‡½ß°IDATxœcÅp‘(…; úÙ[Fã\IEND®B`‚ and the other normal html that uses bar.php displays the table but doesnt seem to be able to retrieve the bar.php in the last coumn... does it work on your system? Quote Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted April 1, 2007 Author Share Posted April 1, 2007 if i take the gd2.dll file from the php.net site it says the function is not recognised but if i use the one thats allready on my system the above random txt comes up... i think i need an extension for the png file ? Quote Link to comment Share on other sites More sharing options...
Barand Posted April 1, 2007 Share Posted April 1, 2007 png support is built in to the gd extension If you run <?php phpinfo(); ?> You will get a list of supported formats. When I run the sample html I get the attachd image. If I run bar.php on its own with no query string I get a grey rectangle [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted April 1, 2007 Author Share Posted April 1, 2007 okay so erm ...what shal i do now ? Quote Link to comment Share on other sites More sharing options...
Barand Posted April 1, 2007 Share Posted April 1, 2007 is bar.php in the same folder as the test html sample file? Quote Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted April 1, 2007 Author Share Posted April 1, 2007 yes same folder the code that i have used from urs is in the exact format as below: UNTITLED2.PHP <html> <head> <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <META http-equiv="content-language" content="en"> <META name="author" content="Barand"> <META name="generator" content="PHPEd 4.5"> <title>Bar sample</title> </head> <body> <table width="884" border='1'> <tr> <td width="122"> Item A </td> <td width="58"> 20 </td> <td width="303"> <img src='bar.php?val=20&max=50' border="0"> </td> </tr> <tr> <td height="42"> Item B </td> <td> 40 </td> <td> <img src='bar.php?val=40&max=50'> </td> </tr> <tr> <td> Item C </td> <td> 30 </td> <td> <img src='bar.php?val=30&max=50'> </td> </tr> <tr> <td> Item D </td> <td> 50 </td> <td> <img src='bar.php?val=50&max=50'> </td> </tr> </table> </body> </html> bar.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php // set dimensions $w = 102; $h = 12; // create image $im = imagecreate($w, $h); // set colours to be used $bg = imagecolorallocate($im, 0xE0, 0xE0, 0xE0); $black = imagecolorallocate($im, 0x00, 0x00, 0x00); $barcolor = imagecolorallocate($im, 0xFF, 0x00, 0x00); // draw border imagerectangle($im, 0,0,$w-1,$h-1,$black); // get value and max value from query string $val = isset($_GET['val']) ? $_GET['val'] : 0; $max = isset($_GET['max']) ? $_GET['max'] : 100; // calculate dimensions of inner bar $barw = $max ? floor(($w-2) * $val / $max) : 0; $barh = $h - 2; // draw inner bar if ($barw) imagefilledrectangle($im, 1, 1, $barw, $barh, $barcolor); // send image header header("content-type: image/png"); // send png image imagepng($im); imagedestroy($im); ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Barand Posted April 1, 2007 Share Posted April 1, 2007 What does this give <?php echo '<pre>', print_r(gd_info(), true), '</pre>'; ?> I get Array ( [GD Version] => bundled (2.0.28 compatible) [FreeType Support] => 1 [FreeType Linkage] => with freetype [T1Lib Support] => 1 [GIF Read Support] => 1 [GIF Create Support] => 1 [JPG Support] => 1 [PNG Support] => 1 [WBMP Support] => 1 [XPM Support] => [XBM Support] => 1 [JIS-mapped Japanese Font Support] => ) Quote Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted April 1, 2007 Author Share Posted April 1, 2007 Array ( [GD Version] => bundled (2.0.28 compatible) [FreeType Support] => 1 [FreeType Linkage] => with freetype [T1Lib Support] => 1 [GIF Read Support] => 1 [GIF Create Support] => 1 [JPG Support] => 1 [PNG Support] => 1 [WBMP Support] => 1 [XPM Support] => [XBM Support] => 1 [JIS-mapped Japanese Font Support] => ) ITS THE SAME I THINK Quote Link to comment Share on other sites More sharing options...
Barand Posted April 1, 2007 Share Posted April 1, 2007 bar.php should be <?php // set dimensions $w = 102; $h = 12; // create image $im = imagecreate($w, $h); // set colours to be used $bg = imagecolorallocate($im, 0xE0, 0xE0, 0xE0); $black = imagecolorallocate($im, 0x00, 0x00, 0x00); $barcolor = imagecolorallocate($im, 0xFF, 0x00, 0x00); // draw border imagerectangle($im, 0,0,$w-1,$h-1,$black); // get value and max value from query string $val = isset($_GET['val']) ? $_GET['val'] : 0; $max = isset($_GET['max']) ? $_GET['max'] : 100; // calculate dimensions of inner bar $barw = $max ? floor(($w-2) * $val / $max) : 0; $barh = $h - 2; // draw inner bar if ($barw) imagefilledrectangle($im, 1, 1, $barw, $barh, $barcolor); // send image header header("content-type: image/png"); // send png image imagepng($im); imagedestroy($im); ?> remove all the surrounding html code Quote Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted April 1, 2007 Author Share Posted April 1, 2007 AT LAST THE HARD WORK HAS PAID OFF... thanks Barrand....i realy really appreciate your hard work and consisstent help throughout the course of this whole procedure from start to end....great help!! thank you! I fee like sending you a gift ! thanks! :) ;D Quote Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted April 1, 2007 Author Share Posted April 1, 2007 P.S. REMOVING THE SURROUND CODE DID THE JOB....wonder why it didnt work with it...thanks once more again barrand! Quote Link to comment Share on other sites More sharing options...
Barand Posted April 1, 2007 Share Posted April 1, 2007 P.S. REMOVING THE SURROUND CODE DID THE JOB....wonder why it didnt work with it... Placing a gd produced image with < img src='an_image.php' > is the same as placing a static image file (such as jpeg). The only diff is the image is generated on demand from the php code. If you edited a jpeg file and put the html code at the begining and end then that wouldn't work either. Quote Link to comment Share on other sites More sharing options...
ali_2kool2002 Posted April 1, 2007 Author Share Posted April 1, 2007 ohhh i see... something new learnt again..! thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.