C# program that generates html pages - limit image dimensions on page

Posted by Professor Mustard on Stack Overflow See other posts from Stack Overflow or by Professor Mustard
Published on 2010-04-01T22:02:52Z Indexed on 2010/04/01 22:13 UTC
Read the original article Hit count: 513

Filed under:
|
|
|

I have a C# program that generates a large number of html pages, based on various bits of data and images that I have stored on the file system. The html itself works just fine, but the images can vary greatly in their dimensions. I need a way to ensure that a given image won't exceed a certain size on the page.

The simplest way to accomplish this would be through the html itself... if there was some kind of "maxwidth" or "maxheight" property I could set in the html, or maybe a way to force the image to fit inside a table cell (if I used something like this, I'd have to be sure that the non-offending dimension would automatically scale with the one that's being reduced). The problem is, I don't know much about this "fine tuning" kind of stuff in html, and it seems to be a tough thing to Google around for (most of the solutions involve some sort of html specialization; I'm just using plain html).

Alternatively, I could determine the width and height of each image at runtime by examining the image in C#, and then setting width/height values in the html if the image's dimensions exceed a certain value. The problem here is that is seems incredibly inefficient to load an entire image into memory, just to get its dimensions. I would need a way to "peek" at an image and just get its size (it could be bmp, jpg, gif or png).

Any recommendations for either approach would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about c#

Related posts about html