hello chaps.

so basically ive built a script which looks through a 'pictures' directory and then lists the folders. each folder is an album. once you click one it will display all the pics in that folder. fine. except for the fact that its loading all the full images, and resizing them as thumbnails. so obviously this is running VERY slow ... especially when ive got pics that are like 3000px x 3000px ..

so the whole point of this script is that its completely automated. its running on an intranet... so people just drop their pictures into a folder in the shared area on the server... and it works. which it does. its just really slow.

so im wondering if theres any way of making thumbnails on the fly?
i know that i could have an upload script that will make the thumbnails on submit... but this isnt how it can work.

my ideas were perhaps that when the script executes on that folder and the thumbnails are not present... it will make the thumbnails and cache them. so the first time it will be a slow load... but thenafter it is fine.

or perhaps i could have a scheduled task that runs a php script every 5 minutes that checks the directories to see if they have thumbnails and if not, it creates them?

does any body have any ideas? as i dont really want people to load 100 x 3mb pictures at once... its very intensive on the network & server...

Thank you in advance :-)

    Caching thumbnails sounds like a good idea, but you may find that your server is working pretty hard if it stumbles across a folder with lots of large images and no thumbnails.

    I'm curious why you can't build the thumbs when folks upload. This is probably the most efficient way to do it because you build a thumb for each image exactly once at the very beginning.

    A cron job would also work on a linux machine. Or you could schedule a php script to run on a windows machine using the task scheduler.

    Part of the trick here is to make sure that when you generate thumbnails for these pictures that there's no chance of a name conflict with any of the original image. For example if you just generated a thumbnail image of any image and named the thumb image by adding "_thumb" to the end. For example pic named 'pic.jpg' would have 'pic_thumb.jpg' then you might have a problem if someone uploaded two images named 'glove.jpg' and 'glove_thumb.jpg'. You should probably put your thumbs in a subfolder in each folder called 'thumbs' -- of course then you might have issues if someone wanted to name a folder 'thumbs'. Anyways, I think you understand what I'm getting at.

    The functions that will most interest you is probably [man]imagecopyresampled[/man]. There are some code examples in the documentation.

      hi sneakyimp! Thanks for your reply.

      yep i see what you mean about the large folder of un..thumbnailed pics.

      im now thinking i should just have one pic at a time with 'previous' and 'next' buttons to reduce the load. but this would be the easy way out and i wouldnt be getting what i originally set out for.

      the reason im unable to do thumbs on upload, is because people are adding their pictures through the windows explorer environment, ie, copying pictures from their 'my pictures' into a shared folder on their 'my computer'.. the shared folder is located a file/print server.... and the HTTP server is accessing these files via a networked drive.

      it is all windows.

        I wouldn't worry too much about performance unless you have constant activity on this machine -- like if you are serving several thousands of files and thousands of visitors per day.

        The goal is obviously to create a thumbnail exactly once for each image. What happens when someone uploads a new version of a file? If you are checking for thumbnails on the basis of filename alone, then a thumbnail might exist for a previous file that doesn't match the latest file's contents.

          I see a few options with this:
          1: Have a cron job running that processed the large images into the file sizes you need. The processing script checks the create/modify date of the re-sized images against original to ensure the thumbs are up to date. It will also allow you to skip all images that have already been processed. Another option would be for the process script to only check images added since the last time the script ran but this is more likely to fall over.
          2: Create a cache of each image on the fly for each size you need. Again check against the cache date vs the original file. This would provide slower loading times for each user but if some files are never accessed they won't need to be/wont be processed.

          Personally I would go with option 1. It would be simple to implement and provide the best performance for each individual user. You should never need to process the same image twice, It's a waste of cycles and time.

          Ideally the crontab would build an index either in XML or a DBMS (mysql etc...)

            Many thanks for your replies.

            Knowj - your #1 is an excellent suggestion. the images will be rarely changed (mainly social images from colleagues) - i would prefer to lend focus to performance rather than keeping up to date on changes.

            now i just need to learn how to do this

            Cheers guys - your ideas were much appreciated.

              Write a Reply...