Last post Apr 08, 2011 09:18 AM by abhisheks
Apr 04, 2011 11:52 AM|ma111|LINK
I have an e-commerce store with over 1000 products and would like each product to dynamically generate about 5 thumbnails of different sizes. This way staff only need to save one big image and asp.net can generate all the other sizes.
I am wondering what is best practice for dynamically generating this many images. I was thinking dynamically creating them on every page or caching them would be too much. So instead I was thinking I could generate the image once only and save it as a file
on the server which would be linked to on future requests. Then images would only be re-generated when a product image is changed.
Does this sound a good way or doing this, or are there better ways?
Apr 04, 2011 12:20 PM|tehremo|LINK
Go download a copy of nopCommerce (http://www.nopcommerce.com) and look at how they do it. Users upload a single large image and they use a handler to serve up the smaller images. If saves the smaller version to
the file system for future views. You could probably just grab their code and use it.
Apr 04, 2011 12:26 PM|Tripurari Yadav|LINK
in the website you having fix layout and as per layout you have fixed Images Size of all 5 Images.
When you uploading images try to resize that in 5 size and upload in in the five different folder with id of product.
Or upload in the same folder with id and -1. i.e 1-1.jpg, 1-2.jpg
So please see http://forums.asp.net/t/1085119.aspx
Apr 07, 2011 07:23 AM|ma111|LINK
Thanks for your help. Does anyone have any ideas how I can keep the generated thumbnails up to date?
For example if someone updated the original image on the server (outside of my application), the thumbnails wouldn't know the original has updated and wouldn't be generated again. I know generating the thumbnails on every page load would solve this problem,
but wouldn't this be too much if I have over 1000 products? What would be the best approach for this situation?
Apr 07, 2011 01:49 PM|abhisheks|LINK
you can track your image names in db, and when somebody updates the original one, you know what files to delete from file system.
Apr 08, 2011 04:31 AM|ma111|LINK
But would this work if one of our staff overwrote the image on the server directly or by ftp? The filename would still be the same, but the image would be different. Is there a file property I could check on each page load to see if the image has been changed?
It would need to be something which wouldn't affect performance too much on a large website.
Apr 08, 2011 09:18 AM|abhisheks|LINK
Two options I can think of
1) you can either stamp your file with something that you can read to determine whether the file that was uploaded from web server was same or not.
2) You can use the fileinfo class(http://msdn.microsoft.com/en-us/library/system.io.fileinfo.aspx) to determine whether the file that was created or modified fall under certain time range that you expect it to be uploaded from the server. If you upload it
from the web server, the files that were created must fall under certain time range.
In general, though you should rethink about the idea of your staff overwriting the image on the server directly or through ftp. You can not design the system if users can do something like what you mentioned. You are basically writing code to patch up the
deficiency of either users or managers in your company.