This code cuts only: 1, 2, 3 part. If you add another 1 for loop, trim comes from the other end.

$file = "testing3.png"; $size = getimagesize($file); $im = imagecreatefrompng($file); $newIm = imagecreatetruecolor(64, 64); $i = 1; for($y = $size[1] - 64; $y >= 0; $y = $y - 64){ imagecopy($newIm, $im, 0, 0, 0, $y, 64, 64); imagepng($newIm, "cut/" . $i++ . '.png'); } 

demo

  • cut in the normal manner, then resort - teran

1 answer 1

It seems to have turned out, but it does not create 15 pieces, but 18.

 $i = 1; for($xc = 0; $xc <= $size[0]; $xc = $xc + 64){ for($y = $size[1] - 64; $y >= 0; $y = $y - 64){ imagecopy($newIm, $im, 0, 0, $xc, $y, 64, 64); imagepng($newIm, "cut/" . $i++ . '.png'); } }