![]() |
Best way of serving images?
I have a website which serves images in various sizes (e.g. wikipedia allows you to view the same image in different sizes). The images are uploaded by the users of the site.
Currently, I use PHP to process the uploaded images and store them in various sizes in a database (e.g. small/medium/large). What is the best way to serve the images? I can think of: 1) retrieve each image from the database each time it is required. (*** This is the way I currently do it ***) 2) store the images as files in a folder in the public web directory and simply link to them. 3) Using the database-retrieval method, keep a store of previously-requested images in $_SESSION and serve them from $_SESSION each time they are required. Option 2 is probably the most efficient, but I don't like the idea of having a writeable folder in the public web directory. Also, I suspect that doing this would leave the folder open to site-scrapers who could simply retrieve every image stored there. |
I would serve the smallest and link the larger (ie view larger) and then fetch it if they click it
|
You can take advantage of .htaccess to block any 'site-scrapers'.
Option 2 is the best option, with use of .htaccess. Remember that SEO requires that images that are displayed as X width and Y height should be (in its' original dimensions) X width and Y height. Never use code to resize an image. |
Serve your images from the Amazon Cloud and store the common denominator path in the DB. For instance, let's say you have 3 sizes of images. Create three "buckets" in amazon cloud front for each size. Within each bucket, create identical paths to the pictures. Hence, you will have something like: SmallBucket/images/image1.jpg, MediumBucket/images/image1.jpg, BigBucket/images/image1.jpg. All images and paths are the same except for the bucket name.
In your code, you will know when you need a large picture versus a small picture. All you'll need to change is the bucket name within your URL. |
You have shared really very helpful information which is helped me so much and I think it will help to many other people who do not know about it.
|
| All times are GMT +1. The time now is 05:52 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.