Image_Graph can be found at:
http://pear.veggerby.dk
A recent challenge was to get a php graph rendering object to work on linux. My linux installs do not include X, or any GUI, fonts, or graphics libraries. At first pass, the graphing objects worked great on windows, which has GUI libraries and fonts. When deploying on the test linux box, I got a long chain of error messages, due to missing libraries and components. This tutorial will walk you through how to get everything in place on apache, php5, pear, and the file system to make image_graph work like a charm on linux.
If you are getting these errors this site will help:
ERROR: PHP Warning: imagettfbbox(): Could not find/open font in ...
Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open font in /usr/local/lib/php/Image/Canvas/GD.php on line 1194
The font specified cannot be found (c:/windows/fonts/Arial.ttf)! Please specify an existing font...
CONTENTS:
1.
Install Apache
2.
Install PHP with dependencies
3.
Load PEAR
4.
Tweak Image_Graph tests and examples to work
See the apache install guide at this website.
2. Install PHP5 and image_graph dependencies:
PHP required many extra features compiled in.
zlib,
libxml,
freetype,
jpeg support, JPEG programming library (jpegsrc.v6b.tar.gz)
$ tar xfvz ./component (for each component)
$ cd component
$ make
$ su -
$ make install
#For the jpegsrc package, try both:
$ make install
$ make install-lib
After all these dependencies were installed, this configure command did the trick to compile php5 with the necessary linkages:
$ ./configure '--with-config-file-path=/usr/local/apache/conf' '--enable-module=so' '--with-gd' '--with-mysql=/usr/local/mysql/' '--with-ttf' '--with-freetype-dir=/usr/local/freetype2' '--enable-gd-native-ttf' '--with-jpeg-dir=/usr/local/bin/' '--with-zlib-dir=/usr/local/lib' '--with-apxs2=/usr/local/apache/bin/apxs'
$ make
$ su -
$ make install
To prevent an error in image_graph later on, in PHP.INI, set:
allow_call_time_pass_reference = On
Also edit httpd.conf to tell apache that php is installed:
AddType application/x-httpd-php .php .phtml
LoadModule php5_module modules/libphp5.so
Stop and start apache for changes to take effect.
3. Install PEAR Libraries:
PEAR is a convenient way to install php libraries. Image_Graph is part of PEAR and requires a few other PEAR libraries to work.
#this would work, except some dependencies are not yet alpha/stable
$ pear install --alldeps --ignore-errors Image_Graph-alpha
#to install pear libraries not in alpha/stable state, list the package contents:
$ pear remote-info Image_Canvas
Package details:
================
Latest 0.2.1
Installed - no -
Package Image_Canvas
...
Here is the complete list used to setup image_graph using 'pear install'.
$pear install Image_Color
$pear install Log
$pear install Numbers_Roman
$pear remote-info Numbers_Words
$pear install Numbers_Words-0.13.1
$pear install Image_Canvas-0.2.1
$pear install Image_Graph-alpha
4. Setup image_graph PHP code examples:
Now let’s see some graphs!
Unzip the Image_Graph-0.5.0.tar package (
download page), copy the tests folder under Image_Graph-0.5.0\tests onto your webserver. I located the tests under http://server/graph/
At this point:
http://server/graph/tests/gd.php works, with a congratulations message.
http://server/graph/tests/freetype.php breaks with the following message:
The font specified cannot be found (c:/windows/fonts/Arial.ttf)! Please specify an existing font
We need to re-point this to the correct path so it finds the font. Editing freetype.php, you will see some code:
// SPECIFY HERE WHERE A TRUETYPE FONT CAN BE FOUND
$testFont = 'c:/windows/fonts/Arial.ttf';
A Linux server does not come with these fonts. I found image_graph works if you create a folder: /usr/local/lib/php/fonts,
then copy .ttf files out of c:\windows\fonts into that folder. Make sure the files have read access from apache/php.
Remember that linux is case sensitive. I changed the $testfont declaration to:
$testFont = '/usr/local/lib/php/fonts/arial.ttf';
Save the file and refresh http://server/graph/tests/freetype.php and you should get the "Your FreeType installation with GD Words" graphic.
To get the example files running on linux, you’ll need to edit them as well.
Next load up the examples folder in the same manner, so http://server/graph/examples will show the image_graph examples.
You will see they all fails on a similar line:
$Font =& $Graph->addNew('ttf_font', 'Gothic');
To fix it, the line becomes:
$Font =& $Graph->addNew('ttf_font', '/usr/local/lib/php/fonts/gothic.ttf');
To prevent redundancy, create a variable called $GOTHIC in your top level php include file.
//in header file:
$GOTHIC = "/usr/local/lib/php/fonts/gothic.ttf";
//in the graphing files:
$Font =& $Graph->addNew('ttf_font', $GOTHIC);
Now you can confidently use image_graph to make your site dynamically generate graphs on the linux platform!
|
|
|
Copyright © 1999-2008 Outwardmotion