title: Imagick insufficient memory (case 4) on save
body: <p>I'm trying to save an image using Imagick with php.
  When I call <code>saveImage()</code> or <code>saveImageFile()</code> I get</p>
  
  <blockquote>
    <p>Fatal error:  Uncaught exception 'ImagickException' with message 'Insufficient memory (case 4)</p>
  </blockquote>
  
  <p>The image is about 1MB big and the script can use 256MB of memory, which I think should be enough. There is plenty of space available on disk.</p>
  
  <p>What can be the problem?</p>
  
  <p>The code is as follows:</p>
  
  <pre><code>&lt;?php
  list($type, $img) = explode(';', $img);
  list(, $img)      = explode(',', $img);
  $data = base64_decode($img);
  $image = new Imagick();
  $image-&gt;readImageBlob($data);
  $image-&gt;setImageFormat("jpeg");
  $image-&gt;setInterlaceScheme(Imagick::INTERLACE_PLANE);
  $image-&gt;writeImageFile(fopen($name.'-original.jpg','w'));
  ?&gt;
  </code></pre>
  
  <p>If I try to use <code>file_put_contents()</code> instead of <code>saveImage()</code> then an empty file is saved. Perhaps there is a problem with the server configuration?</p>