title: Making non square image render as square image without stretching
body: <p>I have a PHP function that uses Imagick. I am trying to pull a non-square image from a URL and size it up to 500x500px where it doesn't stretch but fits inside this area. Additionally, I am using the Laravel framework and this function is in a controller that is rendered via route.</p>
  
  <pre><code>function myFunction()
  {
  function createGrid()
  {
      $placeholder = "https://placeholdit.imgix.net/~text?txtsize=33&amp;txt=&amp;w=500&amp;h=500";
      $im = new imagick("http://www.masters.com/images/pics/large/h_2015041243595.jpg");
      $image = $im-&gt;resizeImage(500, 500, 0, 0, true);
      // $target = new Imagick($placeholder);
      // $target-&gt;setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
      // $target-&gt;compositeImage($image, imagick::COMPOSITE_COPY, 0, 0);
      header("Content-Type: image/png");
      echo $image-&gt;getImageBlob();
  }
  }
  </code></pre>
  
  <p>I am getting an it rendered as:</p>
  
  <p><a href="https://i.stack.imgur.com/KG33v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KG33v.png" alt="enter image description here"></a></p>
  
  <p>How is $Image not an instance of imagick when it's defined as: </p>
  
  <pre><code>$im-&gt;resizeImage(500, 500, 0, 0, true);
  </code></pre>
  
  <p>What am I doing wrong and how do I fix it?</p>