Currently I am trying to divide an image into 4 other images of the same size from the first one. The result I'm looking for is that the height of the original image is divided by 4 and from there, I get those 4 possible images, each one starting where the height of the next would end. I explain it graphically so you can understand it better:
Expected result
Code with which I managed to get the first cut:
$filename= "imagen.png";
list($w, $h, $type, $attr) = getimagesize($filename);
$src_im = imagecreatefrompng($filename);
$src_x = '0';
$src_y = '0';
$src_w = $w; // ancho
$src_h = $h/4; // alto
$dst_x = '0';
$dst_y = '0';
$dst_im = imagecreatetruecolor($src_w, $src_h);
$white = imagecolorallocate($dst_im, 255, 255, 255);
imagefill($dst_im, 0, 0, $white);
imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
header("Content-type: image/png");
imagepng($dst_im);
print_r($dst_im);
What would be the best way to save the 4 cuts?
Extra: How could I make the number of parts to be trimmed be X instead of 4?