Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Posts
    293
    Thanks
    63
    Thanked 8 Times in 8 Posts

    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.

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,723
    Thanks
    41
    Thanked 191 Times in 190 Posts
    I would serve the smallest and link the larger (ie view larger) and then fetch it if they click it

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #3
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    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.

  • #4
    New Coder
    Join Date
    Jan 2013
    Posts
    16
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #5
    New to the CF scene
    Join Date
    Feb 2013
    Location
    India
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •