Image Thumbnail Mappings
Posted: Tue May 25, 2010 12:08 pm
I have been debating back and forth about which way is better to provide images for entries in a database. For instance, let's take the example of an ecommerce product. I have the product in a mysql database with a prod_id of 1. In the product table is also a description, price, etc. However this product has multiple pictures associated with it, including a "main" avatar type of picture. I could think of a few ways to associate the images, including thumbnails, with the product.
1. Create another table with the url as a text field and the prod_id as a foreign key. Then have another link somehow to a thumbnail url, either in another table or to a self linking reference. This method would require database manipulation and maintenance every time an image is added/deleted.
2. Work off of a directory structure and keep all of product 1's images in a images/prods/1 folder. But then I might have trouble linking the thumbnails unless I used another naming convention in the file name. This would be dynamic in the sense that I could just simple ftp images to the directory, but making sure the naming convention is strict will be a little bit of a manual task.
3. I guess a third option would be to go off of a directory structure again, but use the originals as thumbnails. Wouldn't this be resource intensive?
4. Is there an advantage to mixing the two? For instance, having a directory listing, but mapping the thumbs within a database entry?
I guess my main goal is to make something easy to maintain. I want the adding of images/products to be as automated as possible. I don't need help with the actual code, which is why I posted this in the Theory & Design part. I'm just wondering which one seems better and also which one is setting a trap for the future. Any opinions will be totally appreciated, unless your opinions are about Ethiopian politics in which case they might be only slightly appreciated.
Vin
1. Create another table with the url as a text field and the prod_id as a foreign key. Then have another link somehow to a thumbnail url, either in another table or to a self linking reference. This method would require database manipulation and maintenance every time an image is added/deleted.
2. Work off of a directory structure and keep all of product 1's images in a images/prods/1 folder. But then I might have trouble linking the thumbnails unless I used another naming convention in the file name. This would be dynamic in the sense that I could just simple ftp images to the directory, but making sure the naming convention is strict will be a little bit of a manual task.
3. I guess a third option would be to go off of a directory structure again, but use the originals as thumbnails. Wouldn't this be resource intensive?
4. Is there an advantage to mixing the two? For instance, having a directory listing, but mapping the thumbs within a database entry?
I guess my main goal is to make something easy to maintain. I want the adding of images/products to be as automated as possible. I don't need help with the actual code, which is why I posted this in the Theory & Design part. I'm just wondering which one seems better and also which one is setting a trap for the future. Any opinions will be totally appreciated, unless your opinions are about Ethiopian politics in which case they might be only slightly appreciated.
Vin