我创建了一个代码来生成随机图案图像。它创建一个具有给定宽度和高度的图像,并用 40x40 像素的小矩形填充它。
这是我的代码:
<?php
$width = 1000;
$height = 600;
$image_p = imagecreate($width, $height);
$baseR = 255 - rand(0, 100);
$baseG = 255 - rand(0, 100);
$baseB = 255 - rand(0, 100);
for ($i = 0; $i <= floor($width / 40); $i++){
for ($j = 0; $j <= floor($height / 40); $j++){
$val = floor(100 * (rand(0, 100) / 100));
$r = $baseR - $val;
$g = $baseG - $val;
$b = $baseB - $val;
$color = imagecolorallocate($image_p, $r, $g, $b);
imagefilledrectangle($image_p, $i * 40, $j * 40, (($i + 1) * 40), (($j + 1) * 40), $color);
}
}
imagejpeg($image_p, 'my_dir/test.jpg');
?>
当我将宽度设置为640和高度为400之类的值时,没有问题。但是如果我将宽度设置为1000,高度设置为800,则图像右侧会出现未被覆盖的空白区域由矩形。
我在 delphi 中实现了相同的代码并且它运行得很好,但是在 PHP 中......!
Change imagecreate
to imagecreatetruecolor
您正在创建一个基于调色板的图像,最多包含 255 种颜色。最后分配的颜色用完了,它正在为其余的块回收调色板上的最后一种颜色。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)