我最近阅读了PHP中的图形设计扩展,我正在尝试创建一个不同颜色的正方形。 Example
这是我的计划:
<?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);
?>
但是,此代码仅生成黑色方块。我怎样才能使方形多彩?
答案 0 :(得分:0)
这两个论点几乎不是你想要的:
imagefilledrectangle($image, $i, $i, $maxsize -= 10, $maxsize -= 10, $rescolor);'
^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
此代码的实际功能如下:
$maxsize = $maxsize - 10;
$foo = $maxsize;
$maxsize = $maxsize - 10;
$bar = $maxsize;
imagefilledrectangle($image, $i, $i, $foo, $bar, $rescolor);