It really depends on a few other factors but the simplest pattern for this is the "last-requested-record".
Essentially you're creating a simple transform cache with a periodic cleaner. The idea is that for every hit on a sized asset you record when the hit occurred. If the asset doesn't exist then you generated it obviously. On a regular basis (once a day or whatever), you retrieve a list of all the assets that haven't received a hit in 7 days or 30 days or whatever, and you delete them. This resolves the problem of repeated resizing to a reasonable degree, while remaining reasonably efficient with server space by using the hit timing to give you insight into which assets are actually in use. The major cost is that you're turning a read operation (retrieve existing asset) into a read/write (write hit log, retrieve existing asset). You can trade space for performance by ignoring a percentage of writes (ie, only log hit every 10th time, and run a longer delete cycle). On Mon, Jan 11, 2010 at 9:37 AM, matt_thomson <[email protected]> wrote: > Hi All, > > I have been scratching my head over this problem for a while, and I'm > hoping someone might be able to think of a bright idea, as the > solutions I have at the moment all have some downsides. > > The software is a Joomla photo gallery extension, but the CMS part > isn't that relevant to the problem. > > At the moment, when a gallery is made, lets call it animals, this file > structure is made: > > animals(folder). > -original(folder) > -dogs.jpg (1200 X 800) > -cats.jpg (1600 X 1000) > -fish.jpg (1024 x 800) > > -thumbs(folder) > -dogs.jpg (100 x 75) > -cats.jpg (100 x 60) > -fish.jpg (90 x 75) > > -main(folder) > -dogs.jpg (600 x 400) > -cats.jpg (600 x 350) > -fish.jpg (550 x 400) > > -lightbox(folder) > -dogs.jpg (800 x 600) > -cats.jpg (800 x 500) > -fish.jpg (750 x 600) > > So essentially the images are copied into the animals/original folder. > The thumbs are made (in this case with a max height of 100 and max > width of 75) > The main images are made (max height of 600 and max width of 400) > The lightbox images are made (max height of 800 and max width of 600) > > The administrator can choose the max width/height when making a > gallery. > If you want to see an example of the gallery, there is one here: > http://www.ignitejoomlaextensions.com/ > > This works fine as long as the user wants to display the gallery as > is. > > What I would like the user to be able to do is display the gallery as > is one page 1, but on page 2 display the same gallery at a different > size. (so for example the user might want to do a random animal images > gallery, where the images are smaller/bigger size, on a different > page). > > So the problem is, how do I have different instances (in terms of > size) of the same gallery. > > So far, the ideas I have are: > > 1.) Just download the original image, and let the browser do the > resizing. > Problem, some users upload 2000px wide images, and I don't know what > widths they are going to use, (or are going to use in the future) so I > have to download 30 2000px wide images, and this uses up to much > bandwidth. > > 2.) Make the images on the fly, and try some kind of caching method. > Problem, even with some kind of caching, the gallery images are still > going to be have to remade quite regularly (the gallery will run on > other customers servers, so only php caching is an option). Ideally I > want the user to make a gallery, have the images made, then have the > images downloaded for a month. Not have the gallery made, then have > the images remade 5,000 times over the next month (slowing down the > server). > > 3.)Do a > if( ! file_exists('gallery_images/dogs_600_400.jpg') > { > //go and make the dogs_600_400.jpg (from the original image which is > stored on the server) > //then make a html link for dogs_600_400.jpg > } > else > { > //make a html link for dogs_600_400.jpg > } > > That way if someone wants a instance of the gallery at max 300 x 200, > the gallery will make the dogs_300_200.jpg image, and next time round > just check that they exist. > This seems the best way to me, but there is a minor problem. Users > will create a 300 x 200 module, then change it to 350 x 200, then 355 > x 200.... and extra images get made on the server that are not used. > Trying to detect what is used and what is not is next to impossible, > as users will also be able to put text within Joomla articles going > {gallery gallery="animals" width="300" height ="200"}, (this will put > a gallery into the article), and it is not practical to try and scan > all Joomla content and work out what images are actually needed. > > Ideally I'd like a smart way that doesn't leave a lot of trash that > builds up on the server. If anyone has any smart ideas, they are much > appreciated. > > Thanks, > > Matt. > > -- > NZ PHP Users Group: http://groups.google.com/group/nzphpug > To post, send email to [email protected] > To unsubscribe, send email to > [email protected] >
-- NZ PHP Users Group: http://groups.google.com/group/nzphpug To post, send email to [email protected] To unsubscribe, send email to [email protected]
