Reputation: 169
I am building a database for a website that will be a cataloge of products. I am having a problem with the table of images. I have a php script that resizes the image with three sizes, renames them with a suffix, writes them to a directory and adds a reference to them in a table of images.
I am having trouble figuring out how the thumbnails (the small images) will be associated with the medium and large images since I'm planning to have multiple images for each product. I want to be able to add all thumbnails to a page with a link either to the medium or large image via a php script.
Here is what I have so far,
image-id product-id filename size caption width height alt
13 1 PassPro150_large.jpg large NULL 632 569 NULL
14 1 PassPro150_medium.jpg medium NULL 250 225 NULL
15 1 PassPro150_small.jpg small NULL 115 103 NULL
Is there a standard way to do this? Should I make three tables, one for each size and associate them with a primary-foreign key? I also thought I could do it with string manipulation, replace _small with _large since all images uploaded will have the same postfix. Any suggestions?
Upvotes: 4
Views: 2146
Reputation: 119827
now you will have this format:
imageid_imagenumber_imagesize.jpg
where:
place them somewhere in your website, and you are good to go. no need for a database
as for image dimensions, and other meta data about the image, read more about getting the EXIF data using PHP
Upvotes: 1
Reputation: 157828
I wonder why to use a database for this purpose at all.
Can't you just add a word "small" to the image name and put it in the img tag, along with predefined dimensions?
Upvotes: 2
Reputation: 3794
What Joseph said is one solution. Or you could create multiple folders different sizes of thumbnails, like thumb_small, thumb_medium and save the images in there with same name.
You just keep the filename in the database. and when you need to display the image you adjust the url to the particular folder.
Upvotes: 1