title: circularize an image with imagick
body: <p>Trying to take a rectangular photo, crop it into a square region, and then mask it into a circular with a transparent background.</p>
  
  <pre><code>//$dims is an array with the width, height, x, y of the region in the rectangular image (whose path on disk is $tempfile)
  
  $circle = new \Imagick();
  $circle-&gt;newImage($dims['w'], $dims['h'], 'none');
  $circle-&gt;setimageformat('png');
  $circle-&gt;setimagematte(true);
  $draw = new \ImagickDraw();
  $draw-&gt;setfillcolor('#ffffff');
  $draw-&gt;circle($dims['w']/2, $dims['h']/2, $dims['w']/2, $dims['w']);
  $circle-&gt;drawimage($draw);
  
  $imagick = new \Imagick();
  $imagick-&gt;readImage($tempfile);
  $imagick-&gt;setImageFormat( "png" );
  $imagick-&gt;setimagematte(true);
  $imagick-&gt;cropimage($dims['w'], $dims['h'], $dims['x'], $dims['y']);
  $imagick-&gt;compositeimage($circle, \Imagick::COMPOSITE_DSTIN, 0, 0);
  $imagick-&gt;writeImage($tempfile);
  $imagick-&gt;destroy();
  </code></pre>
  
  <p>The result is the rectangular image, uncropped and without being circularized.  What am I doing wrong?</p>
  
  <p>Example image: 
  <img src="https://i.stack.imgur.com/VDSlU.jpg" alt="enter image description here"></p>
  
  <p>Example input for $dims = {"x":253,"y":0,"x2":438.5,"y2":185.5,"w":185.5,"h":185.5}</p>
  
  <p>Rough expected output: </p>
  
  <p><img src="https://i.stack.imgur.com/byXh3.png" alt="enter image description here"></p>
  
  <p>Image i'm getting looks roughly like the input image.</p>