> Calculate imageScale from current size to final size
> While (imageScale < 50%) {
> scale image down by 50%
> recalculate imageScale from current size to final size
> }
Can't agree more. I've used myself exactly same algorithm successfully
multiple times. If you don't want to implement this in JAI chain you can
use SwingX library that provides implementation of this algorithm in
ready to use format.
Maybe to come bit back to the original discussion about whether to
process images on the fly or keep preprocessed images in the repo. While
I agree that processing power is not as critical today as it used to be
few years back and java is way faster at processing images then it used
to be then, there are still other issues to be considered when deciding
final solution, for example
- how many rescaled images are you going to show at once?
Imagine that you have full size images in the repo, each about 3-5MB
size and your page is showing thumbnails of those images, say 20 at a
time. In this case even if it takes only 200ms per image (and that is
quite optimistic since you need to load, rescale and send thumbnail to
the client), you are still looking at 20x200ms = 4sec to load all the
images. And those are the extra 4 seconds the first user looking for the
page will have to wait before having it loaded. And remember that with
default caching strategy all those cached rescaled images will be gone
once you activate another piece of content ...
- Another consideration is total amount of images that will need to be
rescaled and the load on your site. If you have 1k+ images and moderate
to high traffic, it will happen that multiple users will request not yet
cached images at same time. If you ever observed CPU while doing any
image processing, you know that normally usage goes quite high and if
having to serve multiple images at a same time you can easily choke your
server and render it non responsive for a while.
- Last but not least I would like to mention compression of the JPEG
images. If you have your jpegs highly compressed they will use much more
memory at runtime while being processed as they need to be expanded
first ... no big deal if you have enough server memory just something to
be aware of.
Cheers,
Jan
----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[EMAIL PROTECTED]>
----------------------------------------------------------------