[thelist] JS: Resizing an image?

Juha Suni juha.suni at ilmiantajat.fi
Fri Aug 26 02:39:57 CDT 2005


Frank wrote:
> I'm trying to resize an image by using javascript. The user will
> upload an image, the image will float left in a div. Right now, if
> the div has a lesser height, the image sticks out, if the div has a
> greater height, the images floats loosely. I want to make it so that
> the height of the image always matches the height of the div. In this
> case, it usually means re-adjusting it's dimension by some 2-15px.
> It's just one of those things use to satisfy picky designers.

Letting the browser resize images to different sizes produces utter crap 
with no real resampling. I would strongly encourage you to use a serverside 
scripting language (such as PHP where resizing images is rather easy) to 
resize the images either when the user uploads them, or on the fly if 
necessary (more CPU intensive, but can work pretty well if there are only a 
few images to process).

For info about PHP and image resizing see either the GD functions at 
http://fi.php.net/gd, or check out ImageMagick (which you can use through 
PHP) at http://www.imagemagick.org.

-- 
Suni 



More information about the thelist mailing list