Page 1 of 2

Resizing images at runtime?

Posted: Wed Feb 11, 2009 5:39 pm
by allspiritseve
Does it make sense to resize images at runtime instead of when they're uploaded? I'm thinking that image size is a display concept, and all I would need to do is set the size I need when I display it. The object can then either grab the image if it exists at that size, or resize the raw image to fit. Does that seem like an ok approach? Are there any pitfalls I might encounter doing it this way?

Re: Resizing images at runtime?

Posted: Wed Feb 11, 2009 6:01 pm
by alex.barylski
Yes it makes sense to generate dynamically, just cache the result so you don't suffer the performance hit next time.

Re: Resizing images at runtime?

Posted: Wed Feb 11, 2009 6:02 pm
by allspiritseve
PCSpectra wrote:Yes it makes sense to generate dynamically, just cache the result so you don't suffer the performance hit next time.
Exactly. If it's not already resized, the image gets resized and saved so the next lookup can just load it.

Re: Resizing images at runtime?

Posted: Wed Feb 11, 2009 6:04 pm
by alex.barylski
There ya go. :P

I don't think it's a matter of "does it make sense" so much as it is "is it worth the extra effort". In which I say, you only ever get back, exactly what you put in. :)

Re: Resizing images at runtime?

Posted: Sun Feb 15, 2009 7:51 pm
by josh
On marinas.com our images come in at 10MB + so we had to generate ahead of time. You can zoom in on the high resolution images though which does the resize in real time

Re: Resizing images at runtime?

Posted: Mon Feb 16, 2009 4:24 pm
by allspiritseve
josh wrote:On marinas.com our images come in at 10MB + so we had to generate ahead of time. You can zoom in on the high resolution images though which does the resize in real time
In that case I would probably resize a 1024x768 or so image, and use that image when resizing at runtime. Though I suppose it depends on where the image is going to be used... if you need the detail of that 10MB image, you probably aren't just uploading to a photo gallery or placing a side image in an article.

Re: Resizing images at runtime?

Posted: Mon Feb 16, 2009 4:37 pm
by Benjamin
I would think it best to resize them as they are uploaded. If there are lots of images to be resized, I wouldn't want to add that extra burden during periods of heavy traffic.

Re: Resizing images at runtime?

Posted: Mon Feb 16, 2009 4:46 pm
by allspiritseve
astions wrote:I would think it best to resize them as they are uploaded. If there are lots of images to be resized, I wouldn't want to add that extra burden during periods of heavy traffic.
I don't always know what size I'm going to need until later though. Sometimes the design changes, and I need a different version of all of the images I have already uploaded. If I resize them at runtime, then I can set the size I need in the template (which makes a lot of sense to me). That doesn't mean that each image needs to be resized for every page load though... once it's resized then that size gets saved and reused.

Re: Resizing images at runtime?

Posted: Mon Feb 16, 2009 4:48 pm
by Benjamin
So these are all variable sized images? There aren't a set of specific sizes? Then I guess you have to resize them once the first time they are loaded and just cache them.

Re: Resizing images at runtime?

Posted: Mon Feb 16, 2009 9:43 pm
by josh
Sizing from 1024 down to thumbnail still takes forever, If I needed to change the design in a pinch I could switch to "lazy" resizing, but if the image base + design don't need to change frequently aggressive loading wins performance wise in my book. Thing is if you have a page of 50 thumbnails or something even shaving .01 off your load time is noticeable to the end user

Re: Resizing images at runtime?

Posted: Mon Feb 16, 2009 9:53 pm
by allspiritseve
josh wrote:Sizing from 1024 down to thumbnail still takes forever, If I needed to change the design in a pinch I could switch to "lazy" resizing, but if the image base + design don't need to change frequently aggressive loading wins performance wise in my book. Thing is if you have a page of 50 thumbnails or something even shaving .01 off your load time is noticeable to the end user
Noticeable to one user only, though. Who very well could be the developer, designer, the client, etc. As opposed to me having to write a custom resize script to go through and resize all the images that have already been uploaded.

Re: Resizing images at runtime?

Posted: Tue Feb 17, 2009 1:54 am
by josh
Well n images mean it effects <= n users, so 120k images on marinas.com would mean 120k different images, lets say we were under peak load and it was taking .4 seconds to resize... that'd be 13hrs of wasted CPU cycles ( if every image got hit ), not to mention you'd be flooding your disk queue, all to save 20 minutes of coding ( then the resizing takes place off site which takes 4+ days )

Re: Resizing images at runtime?

Posted: Tue Feb 17, 2009 12:07 pm
by allspiritseve
josh wrote:Well n images mean it effects <= n users, so 120k images on marinas.com would mean 120k different images, lets say we were under peak load and it was taking .4 seconds to resize... that'd be 13hrs of wasted CPU cycles ( if every image got hit ), not to mention you'd be flooding your disk queue, all to save 20 minutes of coding ( then the resizing takes place off site which takes 4+ days )
I'm not sure what you're trying to prove, obviously resizing at runtime wouldn't be the right fit for a site like that, but that doesn't mean it wouldn't work for other situations. Also, I can bet that you probably already know the size requirements up front for these images, since your site is very image-centric.

Re: Resizing images at runtime?

Posted: Tue Feb 17, 2009 1:32 pm
by josh
Not trying to prove anything just saying it depends on context, was just pointing out the contra-example, we're actually discussing changing the way we do it right now

Re: Resizing images at runtime?

Posted: Tue Feb 17, 2009 1:42 pm
by allspiritseve
josh wrote:Not trying to prove anything just saying it depends on context, was just pointing out the contra-example, we're actually discussing changing the way we do it right now
Gotcha. I don't even know if this is something I'd use for a photo gallery, as that would be better done batched. When user-uploaded images are inset into pages, articles, blogs, etc., though, we've traditionally had a couple of different sizes of each image made automatically, but that hasn't been working very well when requirements change.