dongyou1926 2011-03-09 14:49
浏览 49
已采纳

ImageGD未正确填充

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

$canvas = 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?

  • 写回答

1条回答 默认 最新

  • duanbi8529 2011-03-11 21:51
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退