doujian4752 2013-05-21 16:05
浏览 19

平面设计程序不起作用

I recently read about graphic design extensions in PHP and I am trying to create a square with different colors. Example.

Here is my program:

<?php
$color = array(0 => array('35', '3B', '1A'),
               1 => array('7E', 'A6', '29'),
               2 => array('D9', 'C9', '9A'),
               3 => array('D9', '30', '30'),
               4 => array('73', '07', '10'),
               5 => array('D9', '62', 'C6')
               );
$image = imagecreate(200,200);
$maxsize = 200;
$currentcolor = 0;
$yellow = imagecolorallocate($image, 0xFF, 0xFF, 0x00);
for($i = 0; $i <= 200; $i += 10) {
    if($currentcolor == 6) {
        $currentcolor = 0;
    }
    $red = "0x".$color[$currentcolor][0];
    $green = "0x".$color[$currentcolor][1];
    $blue = "0x".$color[$currentcolor][2];
    $red = (int)$red;
    $green = (int)$green;
    $blue = (int)$blue;
    $rescolor = imagecolorallocate($image, $red, $green, $blue);
    imagefilledrectangle($image, $i, $i, $maxsize -= 10, $maxsize -= 10, $rescolor);
    $currentcolor++;
}
header("Content-Type: image/png");
imagepng($image);
?>

However, this code produces only a black square. How can I make the square multicolored?

  • 写回答

1条回答 默认 最新

  • douyunjiaok300404 2013-05-21 16:12
    关注

    These two arguments are almost CERTAINLY not what you want:

    imagefilledrectangle($image, $i, $i, $maxsize -= 10, $maxsize -= 10, $rescolor);'
                                         ^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^
    

    This code is actually functioning as:

    $maxsize = $maxsize - 10;
    $foo = $maxsize;
    $maxsize = $maxsize - 10;
    $bar = $maxsize;
    imagefilledrectangle($image, $i, $i, $foo, $bar, $rescolor);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分