开发者

ImageGD not filling correctly

Hay, I'm using this code to generate an image and fill it with a gray colour.

$ca开发者_StackOverflow社区nvas = imagecreatetruecolor(100, 100);
$gray = imagecolorallocate($canvas, 0xEE, 0xEE, 0xEE);
imagefill($canvas, 0, 0, $gray);    
imagegif($canvas);

This works fine, but if i change the canvas size to a 'long' image, it fails to fill.

$canvas = imagecreatetruecolor(1, 100);

Is this a common bug? Or do i need some other option? How do i fill the whole canvas?


Looks like a bug. I confirm the same behavior. It fills only top 2 pixels, if you specify the width to be 1. The similar for 2 or 3. 4 seems like a magic value - it begins to work there.

On the other hand this bug doesn't seem to appear if you use a 1px-high image, i.e. I tried this and it worked as expected:

$canvas = imagecreatetruecolor(100, 1);                                                                                                                 
$red = imagecolorallocate($canvas, 0xEE, 0, 0);                                                                                                         
imagefill($canvas, 0, 0, $red);                                                                                                                     
imagegif($canvas, "output.png");  

So this might be a kind of a workaround.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜