Very strange behaviour of imageftbbox()? [message #173006] |
Wed, 16 March 2011 18:04 |
The Natural Philosoph
Messages: 993 Registered: September 2010
Karma:
|
Senior Member |
|
|
I am chasing a very very weird bug..
I have some code, which works 100% solidly on one machine, but
*randomly* fails WITH EXACTLY THE SAME INPUT DATA on another.
That is, when involved with the same data, it works, or sometimes it
doesn't.
What the bit of code does, is center a bit of text in an image. To do
this, it needs to know how wide the text is..so it calls this
and subtracts it from the X value of the text center
e.g.
imagettftext ( $image ,$fontsize,0,
$dest_x+$cx - textoffset($fontsize,$font,$label),
$dest_y+$cy-80,$ivory ,$font,$label);
and..
function textoffset($size,$font,$string)
{
$tmp=imageftbbox( $size, 0.0,$font,$string);
return(($tmp[2]-$tmp[0])/2);
}
On one machine with as near as I can judge identical software, albeit on
a 32 bit rather than 64 bit platform, sometimes the text is in the right
place, but sometimes it's displaced well to the right, and sometimes
it's simply not there at all - presumably right off the edge of the
image altogether.
Now I stress that this does not change with the parameters supplied to
the program. The same parameters to the same program will produce
different results depending on some condition I have not established.
Now for a bit more information. The actual php code is used to generate
these images is called by <img> statements in another php program's output.
If a single instance of this code is running, I have not yet made it break.
BUT if I call up several instances - i.e. the web browser calls for
half a dozen instances of the program simultaneously via several
slightly different <img> statements in the same page, that seems to be
when the problem happens.
Is it possible that some part of the GD library is not re-entrant?
That's the only thing I can think of..or do you know better?
|
|
|