title: Trimming extra white background from image using ImageMagick in PHP
body: <p>I have a series of images that I am converting to thumbnails using PHP ImageMagick.  The images are JPEG files of products on plain white backgrounds.  The white space around the images are uneven so I want to trim away the extra background.  Here is what I have tried:</p>
  
  <pre><code>$im = new Imagick($imgurl);
  $im-&gt;trimImage(0);
  $im-&gt;thumbnailImage(200,0);
  $im-&gt;writeImage("thumb/".$imgurl);
  </code></pre>
  
  <p>This works as far as the <code>thumbnailImage()</code> is concerned creating a thumbnail that is 200 px wide, but the <code>trimImage()</code> does not have any effect leaving me with the same amount of surrounding whitespace as in the original image.</p>
  
  <p>Can anyone suggest where I am going wrong or how else I might achieve this.  I understand that <code>imagemagick</code> <code>trimImage()</code> can use fuzz, but I couldn't find a good example of how this should be used.</p>
  
  <p>Here is a sample image:</p>
  
  <p><img src="https://i.stack.imgur.com/kRJ1g.jpg" alt="enter image description here"></p>