FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Very strange behaviour of imageftbbox()?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Very strange behaviour of imageftbbox()? [message #173006] Wed, 16 March 2011 18:04 Go to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
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?
Re: Very strange behaviour of imageftbbox()? [message #173240 is a reply to message #173006] Tue, 29 March 2011 07:19 Go to previous message
gordonb.3puav is currently offline  gordonb.3puav
Messages: 1
Registered: March 2011
Karma: 0
Junior Member
> 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.

What creates these files in the first place? How are unique names
guaranteed? What guarantee is there that one of the files won't
be overwritten by one of the other files, *WHILE* your code is
running?

> 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?
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Failed @getimagesize() print to error_log?
Next Topic: ip address of client
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 04:43:18 GMT 2024

Total time taken to generate the page: 0.03100 seconds