Answer the question
In order to leave comments, you need to log in
How to crop an image in this order?
I have this picture.
How to cut it into 64x64 pieces in the right order using php?
<?php
foreach(glob("cut/*") as $file){
unlink($file);
}
$imageFile = "test.png";
list($width, $height) = getimagesize($imageFile);
$image = imagecreatefrompng($imageFile);
$newImage = imagecreatetruecolor(64, 64);
$index = 1;
for($x = 0; $x <= $width; $x += 64){
for($y = $height - 64; $y >= 0; $y -= 64){
imagecopy($newImage, $image, 0, 0, $x, $y, 64, 64);
imagepng($newImage, "cut/" . $index++ . '.png');
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question