The system I’m developing at the moment will enable users to upload images. Upon upload, several thumbnail versions of the image are created. I also plan to create a database entry for every image upload.
This is how I plan to do it all:
Member images folder: myapp/images/members/
Within this folder I will create seperate folders for each member: myapp/images/members/$member_id
Images are uploaded to the member folder, the original filename is appended with "_main" , "_thumblarge" or "_thumbsmall" depending on the version of the image. I retain the original file extension by using the "extensionName" property of CUploadedFile.
Now when creating the entry in the DB how should the image be referenced? For example suppose the original image is called "abcxyz.jpg" - this will have 3 versions: "abcxyz_main.jpg", "abcxyz_thumblarge.jpg" and "abcxyz_thumbsmall.jpg".
I don’t think we need 3 seperate columns in the DB, but we do need to know what files to look for. Anybody got any thoughts on this?
Yeah I think the slight difficulty would be with the extension - if I just store the filename without the extension, it won’t find the file(s). Similarly if I store the full filename, i.e. abcxyz.jpg then I have to do a split and insert the suffix. Perhaps I can just include an “extension” field in the DB?
Do you really need to store images names? All images have ids, so you can name them “253_s.jpg” for small, “253_b.jpg” for big and etc. Maybe you’ll only need to save original image name, because it’s extension can be different. Here I assume you resize images to jpg format.
-an approach would be save the filename and add the "_main" or other suffix before you output
-another one is to have 2 fields on the table, 1 for the name, 1 for the path of the file and alter the filename adding "_main" as suffix and then you have the original name, which is better can the user will be able to change the image name without alter the file
save the thumbnails sufixed with its size instead of "_big" and "_small", like "image1_128_128.png"
at somet point you might want to create a new type of thumbnail and it wont look good to call it "_smaller" and then "_smallest"
also its better for remembering like "img_64.jpg" you will know that its size is 64px x 64px without think twice
Do you think it would be best to resize all images to jpg? For example if a user uploaded a GIF should it be converted to jpg and would it make any difference to the file? That way I don’t actually have to worry about extensions…
OR should it always be resized in the format of the original file?