PHP GD 中是否有最大数量的 "Draws"
Is there a maxium amount of "Draws" in PHP GD
正如标题所说,您可以使用 PHP 中的 GD 库绘制最大数量 objects。根据下面的代码,我只能显示大约 140 个方块。底部的线条和方块仅在您未首先最大化网格时显示。有人知道完成此操作的另一种方法吗?
<?php
header('Content-type: image/png');
$png_image = imagecreate(3000, 3000);
imagecolorallocate($png_image, 15, 142, 210);
$gridx = 100;
$gridy = 100;
$count = 0;
$currentx = 0;
$currenty = 0;
function makeRec($xpos, $ypos, $c1, $c2, $c3) {
global $png_image, $currentx, $currenty;
imagefilledrectangle($png_image, $xpos, $ypos, $xpos+10, $ypos+10, imagecolorallocate($png_image, $c1, $c2, $c3));
$currentx = $xpos+11;
}
function makexLine($xpos, $ypos) {
global $png_image, $currentx, $currenty;
imageline($png_image, $xpos, $ypos, $xpos, $ypos+10, imagecolorallocate($png_image, 0, 0, 0));
$currentx = $xpos+1;
}
function makeyLine($xpos, $ypos) {
global $png_image, $currentx, $currenty;
imageline($png_image, $xpos, $ypos, $xpos+100, $ypos, imagecolorallocate($png_image, 0, 0, 0));
$currenty = $ypos+1;
}
for($y = 0; $y < $gridy; $y++) {
makeyline($currentx, $currenty);
for($x = 0; $x < $gridx; $x++) {
makexLine($currentx, $currenty);
if($count == 0) {
makeRec($currentx, $currenty, 255, 1, 255);
$count++;
}
else {
makeRec($currentx, $currenty, 255, 255, 255);
$count = 0;
}
}
makexLine($currentx, $currenty);
$currentx = 0;
$currenty = $currenty + 11;
}
makeyline(0, 200);
makeRec(200, 200, 255, 1, 255);
imagepng($png_image);
imagedestroy($png_image);
?>
运行 我系统上的一个测试脚本在棋盘模式中用 imagefilledrectangle()
绘制了 100 万个正方形,效果很好(而且速度出奇地快)。如果有抽奖限制,它至少有那么高。
您的问题似乎是对 imagecolorallocate()
的调用过多。下面我修改了您的代码,使每种颜色仅调用一次 imagecolorallocate()
:
header('Content-type: image/png');
$png_image = imagecreate(3000, 3000);
imagecolorallocate($png_image, 15, 142, 210);
$magenta = imagecolorallocate($png_image, 255, 1, 255);
$black = imagecolorallocate($png_image, 0, 0, 0);
$white = imagecolorallocate($png_image, 255, 255, 255);
$gridx = 100;
$gridy = 100;
$count = 0;
$currentx = 0;
$currenty = 0;
function makeRec($xpos, $ypos, $colour) {
global $png_image, $currentx, $currenty;
imagefilledrectangle($png_image, $xpos, $ypos, $xpos+10, $ypos+10, $colour);
$currentx = $xpos+11;
}
function makexLine($xpos, $ypos, $colour) {
global $png_image, $currentx, $currenty;
imageline($png_image, $xpos, $ypos, $xpos, $ypos+10, $colour);
$currentx = $xpos+1;
}
function makeyLine($xpos, $ypos, $colour) {
global $png_image, $currentx, $currenty;
imageline($png_image, $xpos, $ypos, $xpos+100, $ypos, $colour);
$currenty = $ypos+1;
}
for($y = 0; $y < $gridy; $y++) {
makeyline($currentx, $currenty, $black);
for($x = 0; $x < $gridx; $x++) {
makexLine($currentx, $currenty, $black);
if($count == 0) {
makeRec($currentx, $currenty, $magenta);
$count++;
}
else {
makeRec($currentx, $currenty, $white);
$count = 0;
}
}
makexLine($currentx, $currenty, $black);
$currentx = 0;
$currenty = $currenty + 11;
}
makeyline(0, 200, $black);
makeRec(200, 200, $magenta);
imagepng($png_image);
imagedestroy($png_image);
正如标题所说,您可以使用 PHP 中的 GD 库绘制最大数量 objects。根据下面的代码,我只能显示大约 140 个方块。底部的线条和方块仅在您未首先最大化网格时显示。有人知道完成此操作的另一种方法吗?
<?php
header('Content-type: image/png');
$png_image = imagecreate(3000, 3000);
imagecolorallocate($png_image, 15, 142, 210);
$gridx = 100;
$gridy = 100;
$count = 0;
$currentx = 0;
$currenty = 0;
function makeRec($xpos, $ypos, $c1, $c2, $c3) {
global $png_image, $currentx, $currenty;
imagefilledrectangle($png_image, $xpos, $ypos, $xpos+10, $ypos+10, imagecolorallocate($png_image, $c1, $c2, $c3));
$currentx = $xpos+11;
}
function makexLine($xpos, $ypos) {
global $png_image, $currentx, $currenty;
imageline($png_image, $xpos, $ypos, $xpos, $ypos+10, imagecolorallocate($png_image, 0, 0, 0));
$currentx = $xpos+1;
}
function makeyLine($xpos, $ypos) {
global $png_image, $currentx, $currenty;
imageline($png_image, $xpos, $ypos, $xpos+100, $ypos, imagecolorallocate($png_image, 0, 0, 0));
$currenty = $ypos+1;
}
for($y = 0; $y < $gridy; $y++) {
makeyline($currentx, $currenty);
for($x = 0; $x < $gridx; $x++) {
makexLine($currentx, $currenty);
if($count == 0) {
makeRec($currentx, $currenty, 255, 1, 255);
$count++;
}
else {
makeRec($currentx, $currenty, 255, 255, 255);
$count = 0;
}
}
makexLine($currentx, $currenty);
$currentx = 0;
$currenty = $currenty + 11;
}
makeyline(0, 200);
makeRec(200, 200, 255, 1, 255);
imagepng($png_image);
imagedestroy($png_image);
?>
运行 我系统上的一个测试脚本在棋盘模式中用 imagefilledrectangle()
绘制了 100 万个正方形,效果很好(而且速度出奇地快)。如果有抽奖限制,它至少有那么高。
您的问题似乎是对 imagecolorallocate()
的调用过多。下面我修改了您的代码,使每种颜色仅调用一次 imagecolorallocate()
:
header('Content-type: image/png');
$png_image = imagecreate(3000, 3000);
imagecolorallocate($png_image, 15, 142, 210);
$magenta = imagecolorallocate($png_image, 255, 1, 255);
$black = imagecolorallocate($png_image, 0, 0, 0);
$white = imagecolorallocate($png_image, 255, 255, 255);
$gridx = 100;
$gridy = 100;
$count = 0;
$currentx = 0;
$currenty = 0;
function makeRec($xpos, $ypos, $colour) {
global $png_image, $currentx, $currenty;
imagefilledrectangle($png_image, $xpos, $ypos, $xpos+10, $ypos+10, $colour);
$currentx = $xpos+11;
}
function makexLine($xpos, $ypos, $colour) {
global $png_image, $currentx, $currenty;
imageline($png_image, $xpos, $ypos, $xpos, $ypos+10, $colour);
$currentx = $xpos+1;
}
function makeyLine($xpos, $ypos, $colour) {
global $png_image, $currentx, $currenty;
imageline($png_image, $xpos, $ypos, $xpos+100, $ypos, $colour);
$currenty = $ypos+1;
}
for($y = 0; $y < $gridy; $y++) {
makeyline($currentx, $currenty, $black);
for($x = 0; $x < $gridx; $x++) {
makexLine($currentx, $currenty, $black);
if($count == 0) {
makeRec($currentx, $currenty, $magenta);
$count++;
}
else {
makeRec($currentx, $currenty, $white);
$count = 0;
}
}
makexLine($currentx, $currenty, $black);
$currentx = 0;
$currenty = $currenty + 11;
}
makeyline(0, 200, $black);
makeRec(200, 200, $magenta);
imagepng($png_image);
imagedestroy($png_image);