|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-11-02 21:59 UTC] laszlo dot janszky at gmail dot com
Description:
------------
I'm calling imagecolorallocate and imagettftext functions with random parameters in a loop, but after some call the imagecolorallocate function returns FALSE. I checked the random parameters, but nothing strange about them.
I think the bug is associated with the rand function, because the more I call the rand function, the earlier the bug comes in loop. If I delete the rand from the 5 times I call, and replace it with constant number, the bug comes later in cycle. With this settings it's about character 'w', but not on a constant place, somtimes 'x' or 'y'.
Reproduce code:
---------------
$text=str_split('0123456789abcdefghijklmnopqrstvwxyz',1);
$image=imagecreate(600,50);
$bgcolor=imagecolorallocate($image,0,200,130);
foreach($text as $char)
{
$r=rand(0,30);
$b=255-rand(0,30);
$g=138+rand(-15,15);
$a=rand(0,10);
$l=15+$len*15;
$t=35+rand(-5,5);
$s=20+rand(-2,2);
imagettftext($image,$s,$a,$l,$t,imagecolorallocate($image,$r,$b,$g),'xfont.ttf',$char);
$len++;
}
header("Expires: Mon,26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D,d M Y H:i:S")." GMT");
header("Cache-Control: no-store,no-cache,must-revalidate");
header("Cache-Control: post-check=0,pre-check=0",false);
header("Pragma: no-cache");
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
Expected result:
----------------
I expect to get an image with characters '0123456789abcdefghijklmnopqrstvwxyz' one after the other with different(random) angles and colour.
Actual result:
--------------
I got an image with characters '0123456789abcdefghijklmnopqrstvw', so not the complete character list. And didn't get any error messages or notices with error_reporting(2047).
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 15 10:00:01 2025 UTC |
Nah I wrote wrong code in my previous comment, here is the right one: $c=imagecolorallocate($image,$r,$b,$g); if (!$c) { echo($r.','.$b.','.$g.'<br>'); } imagettftext($image,$s,$a,$l,$t,$c,'xfont.ttf',$char);