A
A
Alex2017-12-15 14:34:28
PHP
Alex, 2017-12-15 14:34:28

How to crop an image in this order?

I have this picture.
5a33b244ee759935535553.png
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');
  }
}

This code works, but instead of 15 chunks it creates more.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-12-15
@frago9876543210

In for replace "<=" with "<"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question