title: PHP picture parts from image (CROP)
body: <p>Hello i have big technical problem i need crop image to parts like this:</p>
  
  <p><img src="https://i.stack.imgur.com/7T6Dj.jpg" alt="enter image description here">
  One parts is 500px x 500px except in the case where there is less space. </p>
  
  <p>Example image size is 1920px x 1080px totaly i have 12 parts of image.</p>
  
  <p>Me problem i have <strong>very big image</strong> it's <strong>30 000px x 20 000px</strong> it's have about <strong>2800part</strong>s. </p>
  
  <p>I try to use php imagemagic library</p>
  
  <p>imagemagic command line codes: <code>http://www.ioncannon.net/linux/81/5-imagemagick-command-line-examples-part-1/</code></p>
  
  <p>with this command i can crop image place: <code>convert flower.jpg -crop 500×500+0+0 flower_crop.jpg</code></p>
  
  <p>first and seconds arguments width height of part: 500;</p>
  
  <p>the third and fourth arguments it's the from the location started clipping;</p>
  
  <p>I tested crop one part per 20 seconds if i need get 2800 parts i need about: <code>2800 x 20 / 60 / 60 = 15-16~ hours</code> I need get fastest result. How i can do it..</p>
  
  <p>full php code:</p>
  
  <pre><code>public function cutImgIntoPieces($imgPieceSizeWidth, $imgPieceSizeHeight, $outputDir) {
      $pieceWidth = $imgPieceSizeWidth;
      $pieceHeight = $imgPieceSizeHeight;
  
      $divWidth = floor($this-&gt;getImgWidth() / $pieceWidth);
      $modWidth = $this-&gt;getImgWidth() % $pieceWidth;
      $divHeight = floor($this-&gt;getImgHeight() / $pieceHeight);
      $modHeight = $this-&gt;getImgHeight() % $pieceHeight;
  
      for ($i = 0; $i &lt;= $divWidth; $i++) {
          for ($j = 0; $j &lt;= $divHeight; $j++) {
  
              $pieceWidth = ($i == $divWidth ? $modWidth : $imgPieceSizeWidth);
              $pieceHeight = ($j == $divHeight ? $modHeight : $imgPieceSizeHeight);
  
              exec("cd ". $this-&gt;getDirName() . " &amp; convert " . $this-&gt;getFullFileName() . " -crop " . $pieceWidth . "x" . $pieceHeight . "+" . $imgPieceSizeWidth * $i . "+" . $imgPieceSizeHeight * $j . " " . $i . "_" . $j . ".jpg");
  
          }
      }
  }
  
  
  
      $img-&gt;cutImgIntoPieces(500, 500, 'C:/xampp/htdocs/');
  </code></pre>