Calls to imagettftext cause fatal error in php
Bill Hernandez
ms at mac-specialist.com
Mon Jul 7 18:49:52 PDT 2008
SUCCESS, SOMEWHAT...
When I installed Zend Debugger 5.5.1 about a year and a half ago, it
came with its own php.ini, and originally had a great deal of trouble
getting it running. It had been compiled in 32 bit mode as best I
understand it, so once I got everything working I posted a message on
4/29/2008 "Getting 32 bit ZendStudio Debugger to work with 64 bit
Apache2 - PHP using MacPorts on Leopard" that provided explicit
instructions on how to get it working.
The message I posted on 4/29/2008 "Getting 32 bit ZendStudio Debugger
to work with 64 bit Apache2 - PHP using MacPorts on Leopard" that
provided explicit instructions on how to get it working, is no longer
valid.
In the later versions of OS X ZEND DEBUGGER DOES NOT require that you
call :
-------------------------------------------------------------------------------
RESTART THE 64 bit APACHE2 using the 32 bit mode ( 'arch -i386' ) :
-------------------------------------------------------------------------------
shell> ~ $ sudo arch -i386 /opt/local/apache2/bin/apachectl start
shell> ~ $ ps aux | grep httpd
-------------------------------------------------------------------------------
ZEND DEBUGGER works fine using 64 bit mode :
-------------------------------------------------------------------------------
shell> ~ $ sudo /opt/local/apache2/bin/apachectl start
shell> ~ $ ps aux | grep httpd
As a carry over from an old version of Zend Debugger 4.x (about 3-4
years old) my php.ini contained :
; [Zend]
extension_dir=/Applications/Zend/ZendStudio-5.5.1/bin/php5
extension=pgsql.so
$ which php
---> /opt/local/bin/php
$ php --version
---> PHP Warning: PHP Startup: Unable to load dynamic library '/
Applications/Zend/ZendStudio-5.5.1/bin/php5/pgsql.so' - (null) in
Unknown on line 0
---> Warning: PHP Startup: Unable to load dynamic library '/
Applications/Zend/ZendStudio-5.5.1/bin/php5/pgsql.so' - (null) in
Unknown on line 0
---> PHP 5.2.6 (cli) (built: Jul 7 2008 15:05:26)
---> Copyright (c) 1997-2008 The PHP Group
---> Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
---> with Zend Debugger v5.2.12, Copyright (c) 1999-2007, by Zend
Technologies
Originally when I tried I got the errors again :
$ php inc_random_image_two.php > zippy.png
---> PHP Warning: PHP Startup: Unable to load dynamic library '/
Applications/Zend/ZendStudio-5.5.1/bin/php5/pgsql.so' - (null) in
Unknown on line 0
---> Warning: PHP Startup: Unable to load dynamic library '/
Applications/Zend/ZendStudio-5.5.1/bin/php5/pgsql.so' - (null) in
Unknown on line 0
$ open zippy.png
But when I opened zippy.png above the image worked.
GOING BACK to the 'PHP Warning' :
Even with the two lines below the [Zend] Apache and PHP seemed to work
fine. I had seen the warnings several times in the logs but never
figured out what to do about it, it turned out it was really simple :
I have a php.ini that contains all my conf stuff, but ZEND DEBUGGER
has its own php.ini, where it also has additional stuff, which is
totally different than it used to be in the previous debugger version.
; [Zend]
; extension_dir=/Applications/Zend/ZendStudio-5.5.1/bin/php5
; extension=pgsql.so
Commenting them out solved the problem, and miraculously
'inc_random_image_two'.php below worked correctly.
THIS time 'php --version' worked correctly also :
$ php --version
PHP 5.2.6 (cli) (built: Jul 7 2008 15:05:26)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
with Zend Debugger v5.2.12, Copyright (c) 1999-2007, by Zend
Technologies
NOW I tried calling 'random_image_sample.php' in Safari, and the image
displayed correctly. The problem with 'imagettftext' dissapeared, or
so I thought. The image displayed correctly as long as I do not use
the ZEND DEBUGGER. If I use the debugger the line containing
'imagettftext' causes the debugger to exit without any warning, or
error message. Its bizarre, because I've never seen the debugger exit
this way.
CONCLUSION : There appears that there were at least two or three
issues causing this problem.
( 1 ) Bufoonery on my part for not resolving the 'PHP Warning' sooner.
( 2 ) The problem between 'imagettftext' and ZEND DEBUGGER.
( 3 ) 'imagettftext' did not work in 32 bit mode even without the ZEND
DEBUGGER.
I had also upgraded all the ports earlier today, but I don't believe
they had anything to do with the image display problem.
I put the code for the two sample pages on here again, in case they
are helpful to others.
<?php session_start(); ?>
<!-- [4325] ( BEGIN ) filename : random_image_sample.php -->
<HTML>
<HEAD>
<TITLE>Random image sample</TITLE>
<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;
charset=iso-8859-1\">
</HEAD>
<BODY>
<?php
$errors=0;
if(isset($_POST['Submit']))
{
$number = $_POST['number'];
if(md5($number) != $_SESSION['image_value'])
echo '<h1>Validation string not valid! Please try again!</h1>';
else
{
echo '<h1>Your string is valid!</h1>';
//do something with the data
}
}
?>
<form name="form1" method="post" action="random_sample.php">
<table cellspacing="0" width="600" align="center">
<tr><td valign="top" align="right">Comments</td>
<td><input name="message" size=40 value="...your message here">
</td></tr>
<tr><td colspan=2 align="center">
<font size="1" face="Geneva, Arial, Helvetica, sans-
serif"><strong><font size="2">
Please enter the string shown in the image in the form.<br> The
possible characters are letters from A to Z in capitalized form and
the numbers from 0 to 9.
</font></td></tr>
<tr><td align="center" colspan=2><input name="number" type="text" id=
\"number\"></td></tr>
<tr><td colspan=2 align="center">
<?php $which_image = 2 ; echo ($which_image == 1) ? '<img
src="inc_random_image_one.php">' : '<img
src="inc_random_image_two.php">' ; ?>
</td></tr>
<tr><td colspan=2 align="center"><input name="Submit" type="submit"
value="Submit"></td></tr>
</table>
</form>
</BODY>
</HTML>
<!-- [4325] ( _END_ ) filename : random_image_sample.php -->
<?php
// <!-- [4327] ( BEGIN ) filename : inc_random_image_two.php -->
// This is example ( 1 ) found on http://us.php.net/imagettftext
header("Content-type:image/png"); //Set the content-type
$image=imagecreatetruecolor(400,30); //Create the image
$white=imagecolorallocate($image,255,255,255); //Create some colors
$grey=imagecolorallocate($image,128,128,128);
$black=imagecolorallocate($image,0,0,0);
imagefilledrectangle($image,0,0,399,29,$white);
$text='Testing...'; //The text to draw
// $font='/[path to font]/Arial.ttf'; //Replace path by your own font
path
$font='/Library/Fonts/Verdana.ttf'; //Replace path by your own font
path
// ZEND DEBUGGER EXITS ON THE NEXT LINE WITHOUT ERROR MESSAGE
imagettftext($image,20,0,11,21,$grey,$font,$text); //Add some shadow
to the text
imagettftext($image,20,0,10,20,$black,$font,$text); //Add the text
imagepng($image); //Using imagepng() results in clearer text compared
with imagejpeg()
imagedestroy($image);
// <!-- [4327] ( _END_ ) filename : inc_random_image_two.php -->
?>
Thanks to all those that helped me with this problem...
Bill Hernandez
Plano, Texas
More information about the macports-users
mailing list