Welcome Guest, Not a member yet? Register   Sign In
Am I doing too many resizes?
#11

[eluser]Colin Williams[/eluser]
I think it's better, if you are concerned about doing them in a string of processes like that, to only create the image when it is requested. Here's a basic rundown of how to do this:

1. Designate a public directory where root (full-size) images will be stored. Let's assume it's /images/
2. Employ mod_rewrite rules on that directory whereby files that do exist get served by Apache and files that do not exist get served by an Image controller.
3. Write the Image controller to catch these exceptions. What you want to do with this is use the URI segments as instructions for processing the image, then store the new image at a location accessible via the exact same URI. After you generate the new image, either serve it dynamically from that controller or redirect to the new file. If you cannot process the image, call show_404()

For example, the file /images/frog.jpg exists. The yet-to-exist thumbnail gets requested at /images/thumbnail/frog.jpg. Since this file doesn't exist, our Images controller is invoked to serve the request. The Images controller processes /images/frog.jpg based on the "thumbnails" preset and writes the file to /images/thumbnail/frog.jpg and then either serves it or redirects to it. Next time /images/thumbnail/frog.jpg is requested, Apache will find that file on the server and serve it per usual. The process only runs once, and only when it must.
#12

[eluser]amipaxs[/eluser]
Quote:Just start with the biggest one and work your way down, using the newly created image as the source for the next. Not the best solution but it saves time and a huge amount of memory, especially when resizing jpg.

GReat! I just reduced resize time for 5 images from 11 to 3 seconds.




Theme © iAndrew 2016 - Forum software by © MyBB