views:

1749

answers:

3

I have an image gallery that is created using a repeater control. The repeater gets bound inside my code behind file to a table that contains various image paths.

The images in my repeater are populated like this

<img src='<%# Eval("PicturePath")' %>' height='200px' width='150px'/>

(or something along those lines, I don't recall the exact syntax)

The problem is sometimes the images themselves are massive so the load times are a little ridiculous. And populating a 150x200px image definitely should not require a 3MB file.

Is there a way I can not only change the image dimensions, but shrink the file size down as well?

Thanks!

+3  A: 

I would recommend creating a handler that can resize images for you on the fly and encode them in whatever format you like.. kind of like a thumbnail generator. This will cost CPU on the server but you can cache images and severely reduce bandwidth costs ETC. Let me see if I can find the link to a good article I read on something similar.

You can look at this article it isn't the one I had read but it has some info about how you can go about implementing this.

Quintin Robinson
You're right about the initial CPU hit on the server for each image, but once cached... +1
JMD
I agree, resizing full images will cost you obs of unnecessary bandwidth.
Pat
+1  A: 

You're looking for the GetThumbnailImage method of the Image class. You will either want to generate the thumbnail images ahead of time or create the image the first time it is accessed and save it to disk for later use (so first access would be slow but subsequent requests would be quick).

John Conrad
A: 

You could try either of these 2 projects on CodePlex.com, both offer dynamic image generation with caching.

The later is straight from Microsoft.

Josh
Yes the codeplex project for the ASP Image Generation is nice, I didn't post that because I didn't want to confuse the control and creating dynamic images from text with reducing the size of existing images.
Quintin Robinson