title: How to create a cropped and centered image with Imagemagick's command line options with variant?
body: <p>I have a Ruby on Rails 5.2 RC2 app that uses <a href="http://edgeguides.rubyonrails.org/active_storage_overview.html" rel="noreferrer">ActiveStorage</a> for hosting images. In particular it's <a href="http://edgeguides.rubyonrails.org/active_storage_overview.html#transforming-images" rel="noreferrer">transforming images</a> with <a href="http://edgeapi.rubyonrails.org/classes/ActiveStorage/Variant.html" rel="noreferrer">variant</a>.</p>
  
  <p>I would like to pass an image, typically of 16:9 or 4:3 ratio and have <code>variant</code> crop it to a specific ratio, width x height, and have it centered. The image could be horizontal or vertical, but the new cropped size is centered.</p>
  
  <p><a href="https://i.stack.imgur.com/X7Vqj.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/X7Vqj.jpg" alt="Image Cropping"></a></p>
  
  <p>From the <a href="https://www.imagemagick.org/script/command-line-options.php" rel="noreferrer">Imagemagick Command Line Options documentation</a>, I have the following:</p>
  
  <p><code>&lt;%= image_tag @photo.image.variant(extent: "1:1", crop: "800x800").processed.service_url %&gt;</code></p>
  
  <p>It creates a square crop, but it's not centered. It defaults to the left. <strong>How do I create a cropped image that's centered with Imagemagick's command line option?</strong></p>
  
  <p>I'm looking for a solution that should work on any image size or aspect ratio. I believe any resizing works off of the originally uploaded image for creation.</p>
  
  <p>For reference, I'm looking to upgrade an older Rails app that uses <a href="https://github.com/carrierwaveuploader/carrierwave" rel="noreferrer">Carrierwave</a>. There is a <code>resize_to_fill</code> that does exactly that. Example code:</p>
  
  <p><code>version :square_thumb do
      process :resize_to_fill =&gt; [200,200]
   end</code></p>