我最近阅读了 PHP 中的图形设计扩展,我正在尝试创建一个具有不同颜色的正方形。例子。
这是我的程序:
<?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);
?>
但是,此代码仅生成一个黑色方块。我怎样才能使正方形五彩缤纷?