title: Optimizing Imagick annotateImage
body: <p>I'm generating images of text using Imagick (think site banners - they look like that). I'm running out of resources on the server in this function, specifically the <code>annotate</code> line.</p>
  
  <pre><code>public function output_image($type = 'png') {
          $this-&gt;set_draw($this-&gt;font_size);
          $this-&gt;image-&gt;newImage($this-&gt;width*1.3, 
              $this-&gt;line_height*2.5, 
              'transparent'); // make an image that's too big
          $this-&gt;image-&gt;annotateImage($this-&gt;draw, 
              $this-&gt;font_size*0.5,  //x offset for cursive fonts
              $this-&gt;font_size, // vertical offset for tall ascenders
              0, //angle
              $this-&gt;text); // add the text
          $this-&gt;image-&gt;trimImage(0); // trim it.
          $this-&gt;image-&gt;setImageFormat($type);
          $this-&gt;base64 = base64_encode($this-&gt;image);
          echo "&lt;img src='data:image/$type;base64,{$this-&gt;base64}'/&gt;"; 
      }
  </code></pre>
  
  <p>On my local environment (win 8.1, xampp, 4gb ram), this is fast.</p>
  
  <p>On the server (godaddy linux, 1 GB ram), it maxes out the resources and it takes 10x longer than it does on my local environment (<strong>up to 4.5 seconds</strong> for sentence-length).</p>
  
  <p>I've timed every function in the class and found that the time is being spent in the line <code>annotateImage()</code>.</p>
  
  <p>I can throw hardware at the problem, but I was wondering if there's a better way to write text on an image? Or a way to speed up how annotate works (lower the image quality, etc)?</p>