0

我想使用 4px png 创建 600px png 叠加图案。这只是重复x轴。

$srcfile = '4px.png';
$outfile = 'overlay.png';
list($src_w,$src_h,$src_type) = getimagesize($srcfile);

$out_w = 600;
$out_h = 600;

$src = imagecreatefrompng($srcfile);
$out = imagecreatetruecolor($out_w, $out_h);

$curr_x = 0;
while($curr_x < $out_w){
    $curr_y = 0;
    while($curr_y < $out_h){
       imagecopy($out, $src, $curr_y, 0, 0, 0, $src_w, $src_h);
       $curr_y += $src_h;
      }
    $curr_x += $src_w;
}

imagepng($out, $outfile, 100);
imagedestroy($src);
imagedestroy($out);

工作 x-repeat 如下

$curr_x = 0;
while($curr_x < $out_w){
    imagecopy($out, $src, $curr_x, 0, 0, 0, $src_w, $src_h);
    $curr_x += $src_w;
}

我如何 Y-repat 上面的代码?

4

1 回答 1

0

我认为,您应该使用两个循环 - 分别用于 x 和 y

$curr_x = 0;
while($curr_x < $out_w) {
    $curr_y = 0;
    while($curr_y < $out_h){
       imagecopy($out, $src, $curr_x, $curr_y, 0, 0, $src_w, $src_h);
       $curr_y += $src_h;
      }
    $curr_x += $src_w;
    }
于 2017-11-18T19:54:14.023 回答