title: Image::Magick (perlmagick) resizing aspect ratio and quality issues (different than convert command line utility)
body: <p>I am attempting to do some bulk resizing operations of images using ImageMagick and perlmagick (Image::Magick).  All of the images I have as sources are large images and I want to resize them down to various intervals or either height or width.  I want to always preserve the aspect ratio.</p>
  
  <p>Given an example image with dimensions of 3840 pixels × 2160 pixels (3840x2160) I want to create the following resized images:</p>
  
  <pre><code>    ?x1000
      ?x500
      ?x100
      1600x?
      1200x?
      800x?
      400x?
  </code></pre>
  
  <p>I can do this very simply using the <em>convert</em> command line utility with the following commands (in order):</p>
  
  <pre><code>    convert input_filename.jpg -resize x1000 output_wx1000.jpg
      convert input_filename.jpg -resize x500  output_wx500.jpg
      convert input_filename.jpg -resize x100  output_wx100.jpg
      convert input_filename.jpg -resize 1600  output_1600xh.jpg
      convert input_filename.jpg -resize 1200  output_1200xh.jpg
      convert input_filename.jpg -resize 800   output_800xh.jpg
      convert input_filename.jpg -resize 400   output_400xh.jpg
  </code></pre>
  
  <p>Since I am attempting to perform these operations in bulk in conjunction with other operations I am attempting to perform these same operations in perl using <em>Image::Magick</em>.  I have tried several different methods with the following results:</p>
  
  <pre><code>#METHOD 1
      my $image = Image::Magick-&gt;new();
      $image-&gt;Read($input_filename);
      $image-&gt;Resize(
          ($width  ? ('width'  =&gt; $width)  : ()),
          ($height ? ('height' =&gt; $height) : ()),
      );
      $image-&gt;Write(filename =&gt; $output_filename);
  </code></pre>
  
  <p>This results in images that do not maintain aspect ratio.  For example, if a height of 100 is supplied, the output image will be the original width by 100 (3840x100).  A comparable effect is had when supplying a width -- the height is maintained, but the aspect ratio is not.</p>
  
  <pre><code>#METHOD 2
      my $image = Image::Magick-&gt;new();
      $image-&gt;Read($input_filename);
      die "Only one dimension can be supplied" if $width &amp;&amp; $height;
      $image-&gt;Resize(geometry =&gt; $width) if $width;
      $image-&gt;Resize(geometry =&gt; "x$height") if $height;
      $image-&gt;Write(filename =&gt; $output_filename);
  </code></pre>
  
  <p>This results in images that <em>maintain aspect ratio</em>, and if the geometry operation is based on height, the output is exactly what is intended.  However, if a width is supplied the output is terribly blurry.</p>
  
  <pre><code>#METHOD 3
      `convert "$input_filename" -resize $width   "$output_filename"` if $width;
      `convert "$input_filename" -resize x$height "$output_filename"` if $height;
  </code></pre>
  
  <p>This results in images that are all correct, but forks outside of the perl process leading to efficiency issues.</p>
  
  <p><strong>Is there a better way in perl to make this resize operation produce the same results as the command-line convert utility?</strong></p>
  
  <p>My command line utility reports version 6.7.9-10, and Image::Magick reports version 6.79.</p>