title: ImageResizer - specify portrait or landscape
body: <p>We want to take a scanned image and determine if it is landscape or portrait, then based on the user's preference of having it rotated to landscape or portrait, rotate it if needed.</p>
  <p>i.e. the user wants it in portrait, but its original format was landscape.</p>
  <p>How do we determine if it is portrait or landscape and then if required, rotate it 90 degrees.</p>
  <p>Trying something like this, but getting stuck on streams not being opened or reset, etc...But more importantly, is this the right/most efficient approach? I don't see any instructions to do this automatically like :<code>desiredAspectRation=Portrait;</code> that would do this already in ImageResizer.net, correct?</p>
  <pre><code>int? imageWidth;
  int? imageHeight;
  
  using (var updatedImageFileStream = new MemoryStream())
  {
      ImageJob imageJob = new ImageJob(origFileStream, updatedImageFileStream,
          new Instructions(strInstructions)
      );
      imageJob.Build();
  
      //change to portrait if required
      imageWidth = imageJob.SourceWidth;
      imageHeight = imageJob.SourceHeight;
  
      if(imageWidth &gt; imageHeight)
      {
          //updatedImageFileStream.Seek(0, SeekOrigin.Begin);
  
          strInstructions = &quot;rotate=90;&quot;;
          imageJob = new ImageJob(updatedImageFileStream, updatedImageFileStream,
              new Instructions(strInstructions)
          );
          imageJob.Build();
      }
  
      updatedImageFileStream.Seek(0, SeekOrigin.Begin);
  
      //upload image to azure
      await azureRepository.UploadAsync(serverRelativePath, updatedImageFileStream, contentType);
      origFileStream.Dispose();
  }
  </code></pre>
  <p><strong>UPDATE</strong></p>
  <p>Got it to work using the below. But not sure it's the most efficient.</p>
  <ul>
  <li><p>Do you need to create a new stream or can <code>ImageJob</code> take the same source and destination to overwrite it...I got an error about cannot access a closed stream when trying, so maybe you do need to create a new stream as I did.</p>
  </li>
  <li><p>I don't like the duplicate call to upload the image(<code>await azureRepository.UploadAsync(serverRelativePath, updatedImageFileStream, contentType);</code>) but I couldn't figure out how to copy the 2nd image stream over the first so I could retain just one call to the <code>UploadAsync</code>. I kept getting cannot access closed stream type errors.</p>
  </li>
  <li><p>am I missing anything else?</p>
  </li>
  </ul>
  <p>Working code, but efficient?</p>
  <pre><code>int? imageWidth;
  int? imageHeight;
  
  using (var updatedImageFileStream = new MemoryStream())
  {
      ImageJob imageJob = new ImageJob(origFileStream, updatedImageFileStream,
          new Instructions(strInstructions)
      );
      imageJob.Build();
  
      //change to portrait if required - WORKS, uncomment if want to do 100% of time, or this is how to implement based on a parameter of &quot;change to Portrait&quot;
      imageWidth = imageJob.SourceWidth;
      imageHeight = imageJob.SourceHeight;
  
      if (imageWidth &gt; imageHeight)
      {
          updatedImageFileStream.Seek(0, SeekOrigin.Begin);
  
          strInstructions = &quot;rotate=90;&quot;;
          var updatedImageFileStream2 = new MemoryStream();
          imageJob = new ImageJob(updatedImageFileStream, updatedImageFileStream2,
              new Instructions(strInstructions)
          );
          imageJob.Build();
  
          updatedImageFileStream2.Seek(0, SeekOrigin.Begin);
  
          //upload image to azure
          await azureRepository.UploadAsync(serverRelativePath, updatedImageFileStream2, contentType);
          updatedImageFileStream2.Dispose();
      }
      else
      {
          updatedImageFileStream.Seek(0, SeekOrigin.Begin);
  
          //upload image to azure
          await azureRepository.UploadAsync(serverRelativePath, updatedImageFileStream, contentType);
      }
  
      origFileStream.Dispose();
  }
  </code></pre>