title: How to get the Image Width & Height when doing Upload in asp.net core
body: <p>I am making a <strong>page in asp.net core</strong> that is <strong>uploading images</strong> to server using <strong>input type file</strong> html control. </p>
  
  <pre><code>&lt;form method="post" asp-action="Add" enctype="multipart/form-data"&gt;
      &lt;input type="file" name="mediaUpload" /&gt;
      &lt;button type="submit"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I have also added the <strong><a href="https://github.com/CoreCompat/CoreCompat" rel="nofollow noreferrer">System.Drawing for .NET Core</a></strong> dll from <strong><a href="https://www.nuget.org/packages/System.Drawing.Common" rel="nofollow noreferrer">NuGet</a></strong>.</p>
  
  <p>Now on my post action I want to get the image Width &amp; Height. This is the below code for it (but its now working).</p>
  
  <pre><code>[HttpPost]
  public ActionResult Add(IFormFile mediaUpload)
  {
      Image image = Image.FromStream(file.OpenReadStream); // error is here
      int width = image.Width;
      int height = image.Height;
  }  
  </code></pre>
  
  <p><em>The complile time error -</em> </p>
  
  <blockquote>
    <p>Severity  Code    Description Project File    Line    Suppression State
    Error CS1503  Argument 1: cannot convert from 'method group' to
    'Stream'  Goldentaurus    E:\Website\Goldentaurus\Goldentaurus\Controllers\MediaController.cs 453 Active</p>
  </blockquote>
  
  <p>Please help??  </p>
  
  <p><strong>Note: My previous ASP.NET MVC 5 application(code shown below) was using a similar code that was working very well. I modified it to the above code to work on asp.net core.</strong></p>
  
  <pre><code>[HttpPost]
  public ActionResult Add(HttpPostedFileBase mediaUpload)
  {
      Image image = Image.FromStream(file.InputStream);
      int width = image.Width;
      int height = image.Height;
  }
  </code></pre>