php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45437 Calls to imagettftext crash
Submitted: 2008-07-06 06:27 UTC Modified: 2008-07-13 00:49 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (100.0%)
From: ms at mac-specialist dot com Assigned: pajoye (profile)
Status: Closed Package: GD related
PHP Version: 5.2.6 OS: OS X 10.5.3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ms at mac-specialist dot com
New email:
PHP Version: OS:

 

 [2008-07-06 06:27 UTC] ms at mac-specialist dot com
Description:
------------
Same exact problem as Bug #44524, which has been written off as bogus. 
IT IS NOT BOGUS...

Problem:
------------
Calls to imagettftext always fail with no error on Leopard 10.5.3
when run under MacPorts Apache 2.2.6, PHP 5.2.5 and the GD library.

Originally I tried the "PHP Form image verification" example at :

http://www.reconn.us/content/view/28/49/

I then tried example ( 1 ) found on http://us.php.net/imagettftext

Both examples failed to display the results and provided not visible 
error, so I fired up the ZEND DEBUGGER and that is when I found the 
culprit, I then checked the Apache error log and found...

Reproduce code:
---------------
<?php
// This is example ( 1 ) found on http://us.php.net/imagettftext

//Set the content-type
header("Content-type:image/png");

//Create the image
$image=imagecreatetruecolor(400,30);

//Create some colors
$white=imagecolorallocate($image,255,255,255);
$grey=imagecolorallocate($image,128,128,128);
$black=imagecolorallocate($image,0,0,0);
imagefilledrectangle($image,0,0,399,29,$white);

//The text to draw
$text='Testing...';
//Replace path by your own font path
// $font='fonts/10.ttf';
$font='/[path to font]/Arial.ttf';

//Add some shadow to the text
imagettftext($image,20,0,11,21,$grey,$font,$text);

//Addthetext
imagettftext($image,20,0,10,20,$black,$font,$text);

//Using imagepng()results in clearer text compared with imagejpeg()
imagepng($image);
imagedestroy($image);
?>



Expected result:
----------------
Small image containing "Testing..."

Actual result:
--------------
Checking the Apache error log shows many instances of :

Break on 
__THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTION
ALITY___YOU_MUST_EXEC__() to debug.

[Sun Jul 06 00:45:18 2008] [notice] child pid 2990 exit signal Trace/BPT 
trap (5)

When I trace Using ZEND DEBUGGER the call to imagettftext shows where 
the break in execution occurs.





Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-06 09:39 UTC] pajoye@php.net
Please provide a link to the font you use.

Also you may send the header right before the PNG generation:

header("Content-type:image/png");
imagepng($image);
imagedestroy($image);


You may look at the contents of the page (show source), If it is a blank page, it may contain error messages not displayed because of the Content-Type.
 [2008-07-06 22:03 UTC] ms at mac-specialist dot com
This includes the three files (which I have renamed to make them 
easier to distinguish), as well as the browser output source :

( 1 ) Main File : random_image_sample.php

( 2 ) Include File : inc_random_image_one.php
       ( a ) 'inc_random_image_one.php' requires "images/noise.jpg", 
which can be downloaded from http://www.reconn.us/images/noise.png
       ( b ) 'inc_random_image_one.php' requires that you copy 10 
different named fonts from /Library/Fonts/  to ./fonts/ and rename 
them from "1.ttf" to "10.ttf"

( 3 ) Include File : inc_random_image_two.php
       ( a ) This is example ( 1 ) found on 
http://us.php.net/imagettftext

<?php
session_start(); 
// <!-- [4325] ( BEGIN ) 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
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_ ) random_image_sample.php -->



<?php
// <!-- [4326] ( BEGIN ) inc_random_image_one.php -->

// This demo requires "images/noise.jpg", which can be downloaded from 
http://www.reconn.us/images/noise.png

// start a session
session_start();
// this function is called recursivelly
function random_string($len=5, $str='')
{
  for($i=1; $i<=$len; $i++)
   {
    // Generates a random number that will be the ASCII code of the 
character. 
    // We only want numbers (ascii code from 48 to 57) and caps 
letters.
    $ord=rand(48, 90);
    if((($ord >= 48) && ($ord <= 57)) || (($ord >= 65) && ($ord <= 
90)))
        $str.=chr($ord);
    // If the number is not good we generate another one
    else
        $str.=random_string(1);
  }
  return $str;
}

// create the random string using the upper function (if you want more 
than 5 characters just modify the parameter)
$rand_str=random_string(5);

// We memorize the md5 sum of the string into a session variable
$_SESSION['image_value'] = md5($rand_str);

// Get each letter in one valiable, we will format all letters 
different
$letter1=substr($rand_str,0,1);
$letter2=substr($rand_str,1,1);
$letter3=substr($rand_str,2,1);
$letter4=substr($rand_str,3,1);
$letter5=substr($rand_str,4,1);

// Creates an image from a png file. If you want to use gif or jpg 
images, just use the coresponding functions: imagecreatefromjpeg and 
imagecreatefromgif.

// You can download "noise.png" at 
http://www.reconn.us/images/noise.png
$image=imagecreatefrompng("images/noise.png");

// $image=imagecreatefromjpeg("images/noise.jpg");

// Get a random angle for each letter to be rotated with.
$angle1 = rand(-20, 20);
$angle2 = rand(-20, 20);
$angle3 = rand(-20, 20);
$angle4 = rand(-20, 20);
$angle5 = rand(-20, 20);

// Get a random font. (In this examples, the fonts are located in 
"fonts" directory and named from 1.ttf to 10.ttf)
// The easiest thing here is to copy 10 different named fonts from 
/Library/Fonts/  to ./fonts/ and rename them
$font1 = "fonts/".rand(1, 10).".ttf";
$font2 = "fonts/".rand(1, 10).".ttf";
$font3 = "fonts/".rand(1, 10).".ttf";
$font4 = "fonts/".rand(1, 10).".ttf";
$font5 = "fonts/".rand(1, 10).".ttf";

// Define a table with colors (the values are the RGB components for 
each color).
$colors[0]=array(122,229,112);
$colors[1]=array(85,178,85);
$colors[2]=array(226,108,97);
$colors[3]=array(141,214,210);
$colors[4]=array(214,141,205);
$colors[5]=array(100,138,204);

// Get a random color for each letter.
$color1=rand(0, 5);
$color2=rand(0, 5);
$color3=rand(0, 5);
$color4=rand(0, 5);
$color5=rand(0, 5);

// Allocate colors for letters.
$textColor1 = imagecolorallocate ($image, 
$colors[$color1][0],$colors[$color1][1], $colors[$color1][2]);
$textColor2 = imagecolorallocate ($image, 
$colors[$color2][0],$colors[$color2][1], $colors[$color2][2]);
$textColor3 = imagecolorallocate ($image, 
$colors[$color3][0],$colors[$color3][1], $colors[$color3][2]);
$textColor4 = imagecolorallocate ($image, 
$colors[$color4][0],$colors[$color4][1], $colors[$color4][2]);
$textColor4 = imagecolorallocate ($image, 
$colors[$color5][0],$colors[$color5][1], $colors[$color5][2]);

// Write text to the image using TrueType fonts.
$size = 20;
imagettftext($image, $size, $angle1, 10, $size+15, $textColor1, 
$font1, $letter1);
imagettftext($image, $size, $angle2, 35, $size+15, $textColor2, 
$font2, $letter2);
imagettftext($image, $size, $angle3, 60, $size+15, $textColor3, 
$font3, $letter3);
imagettftext($image, $size, $angle4, 85, $size+15, $textColor4, 
$font4, $letter4);
imagettftext($image, $size, $angle5, 110, $size+15, $textColor5, 
$font5, $letter5);

header('Content-type: image/jpeg');
imagejpeg($image);		// Output image to browser
imagedestroy($image);	// Destroys the image

// <!-- [4326] ( _END_ ) inc_random_image_one.php -->
?>



<?php
// <!-- [4327] ( BEGIN ) inc_random_image_two.php -->

// This is example ( 1 ) found on http://us.php.net/imagettftext

//Set the content-type
header("Content-type:image/png");

//Create the image
$image=imagecreatetruecolor(400,30);

//Create some colors
$white=imagecolorallocate($image,255,255,255);
$grey=imagecolorallocate($image,128,128,128);
$black=imagecolorallocate($image,0,0,0);
imagefilledrectangle($image,0,0,399,29,$white);

//The text to draw
$text='Testing...';
//Replace path by your own font path
// $font='fonts/10.ttf';
// $font='/[path to font]/Arial.ttf';
$font='/Library/Fonts/Verdana.ttf';

//Add some shadow to the text
imagettftext($image,20,0,11,21,$grey,$font,$text);

//Addthetext
imagettftext($image,20,0,10,20,$black,$font,$text);

//Using imagepng()results in clearer text compared with imagejpeg()
imagepng($image);
imagedestroy($image);

// <!-- [4327] ( _END_ ) inc_random_image_two.php -->
?>



<!-- OUTPUT BROWSER SOURCE -->
<!-- [4325] ( BEGIN ) 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>
<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">
<img src="random_image_two.php"> <!-- THIS IMAGE CONTAINS NOTHING -->
</td></tr>
<tr><td colspan=2 align="center"><input name="Submit" type="submit"
value="Submit"></td></tr>
</table>
</form>
</BODY>
</HTML>
<!-- [4325] ( _END_ ) random_image_sample.php -->
 [2008-07-06 22:45 UTC] pajoye@php.net
We need a small script. It should only contains the image creation, draw some text and save the image, without using any GET/POST/SESSION or whatever else but the ttf file. Something like a 5 lines scripts.
 [2008-07-08 01:52 UTC] ms at mac-specialist dot com
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...

I posted this on the MacPorts forum also, and got some good insights 
there...
 [2008-07-08 06:00 UTC] pajoye@php.net
Sorry, we don't support 3rd party tools like ZendDebugger, ZendCore, XCache or other tools affecting the runtime. Please try without any of these tools using our source releases.
 [2008-07-12 16:08 UTC] akorthaus at web dot de
I have exactly the same problem using Mac OS X 10.4.6, Apache 2 with mod_php (5.2.5), 32-bit. 

Here is a short script to reproduce the error:


----------------------------------------------


<?php
   $im = imagecreate (100, 100);
   $black = imagecolorallocate ($im, 0, 0, 0);
   imageTTFText ($im, 20, 0, 10, 20, $black, './default.ttf', 'TEST');
   imagejpeg ($im);
   imagedestroy ($im);
?>


----------------------------------------------


You can find the 'default.ttf' I used here:
http://www.jtr.de/scripting/php/classes/captcha/index.html (klick "Jax Captcha Class downloaden", you will find the .ttf file in the archive)

PHP/the Apache process crashes and I get a 200 Response from the server without any headers or content.

Here is what the error log writes:


----------------------------------------------


[notice] Accept mutex: flock (Default: flock)
dyld: lazy symbol binding failed: Symbol not found: _FSPathMakeRef
  Referenced from: /usr/local/lib/freetype-2.2.1/lib/libfreetype.6.dylib
  Expected in: flat namespace

dyld: Symbol not found: _FSPathMakeRef
  Referenced from: /usr/local/lib/freetype-2.2.1/lib/libfreetype.6.dylib
  Expected in: flat namespace

[Sat Jul 12 17:49:00 2008] [notice] child pid 3369 exit signal Trace/BPT trap (5)
dyld: lazy symbol binding failed: Symbol not found: _FSPathMakeRef
  Referenced from: /usr/local/lib/freetype-2.2.1/lib/libfreetype.6.dylib
  Expected in: flat namespace

dyld: Symbol not found: _FSPathMakeRef
  Referenced from: /usr/local/lib/freetype-2.2.1/lib/libfreetype.6.dylib
  Expected in: flat namespace

[Sat Jul 12 17:56:41 2008] [notice] child pid 3368 exit signal Trace/BPT trap (5)

----------------------------------------------
 [2008-07-13 00:43 UTC] ms at mac-specialist dot com
Google "Step by step Instructions to fix MacPorts 'freetype' problem"

OR GO TO THE SOLUTION : (This solves the problem)
http://www.mail-archive.com/macports-
users@lists.macosforge.org/msg10379.html

ALSO SEE :
Google "MacPorts imagettftext Hernandez SOLVED"

http://www.mail-archive.com/macports-
users@lists.macosforge.org/msg10396.html
 [2008-07-13 00:49 UTC] ms at mac-specialist dot com
Google "Step by step Instructions to fix MacPorts 'freetype' problem"

OR GO TO THE SOLUTION : (This solves the problem)
http://www.mail-archive.com/macports-
users@lists.macosforge.org/msg10379.html

ALSO SEE :
Google "MacPorts imagettftext Hernandez SOLVED"

http://www.mail-archive.com/macports-
users@lists.macosforge.org/msg10396.html
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 24 10:03:36 2021 UTC