title: PHP ImageMagick split large image to tiles
body: <p>I am trying to split a large image to smaller tiles. I tried it using PHP ImageMagick <code>cropImage()</code> and I could do it successfully with the following code.</p>
  
  <pre><code>for($w = 0; $w &lt; ($large_image_width/$tile_width); $w++){
      for($h = 0; $h &lt; ($large_image_height/$tile_height); $h++){
          $X = $w*$tile_width;
          $Y = $h*$tile_height;
  
          $image = new Imagick($input_file);
          $image-&gt;cropImage($tile_width,$tile_height, $X,$Y);
          $image-&gt;writeImage("X" . ($w+1) . "Y" . ($h+1) . ".jpg");
      }
  }
  </code></pre>
  
  <p>But it loops through each tile size and load the image again and again.</p>
  
  <p>When I did more research, I found this <a href="http://michael.otacoo.com/linux-2/split-an-image-file-into-tiles/" rel="nofollow">link</a>, which is a one liner using the command line. </p>
  
  <pre><code>convert -crop $WIDTHx$HEIGHT@ huge_file.png  tile_%d.png
  </code></pre>
  
  <p>I am wondering if the PHP ImageMagick extension got any function to do the same. Also I am comfortable to switch to Perl or someother library like GD.</p>