Inexpensive way of getting image size in .NET

Associate
Joined
3 Jun 2008
Posts
411
Hi,

Is there a way of getting the dimensions of a .jpg, .png, and .gif in .NET without having to read the entire image which consumes a shed load of memory. If a user uploads a 100000px image to my site, I would just like to discard it without exposing myself to a DoS attack. There must be some kind of libs for getting this from the image header info.
 
I know that ImageMagick has an identify command that will output the type of image and dimensions - you can also install it as a component and use the API on Windows.
 
I know that ImageMagick has an identify command that will output the type of image and dimensions - you can also install it as a component and use the API on Windows.

Thanks, this worked really nicely. I made a 200MB image and identify returned the dimensions instantly :).

There is a .NET wrapper called MagickNet but the website contains viruses according to google?! I went to the site anyway and it seemed fine - no warnings from kaspersky AV.
 
Back
Top Bottom