Image resize function in javascript


function resize(image,dimension,dimension2)
{
var customImage=new Image();
if (dimension == ‘undefined’)
{
dimension=96;
}
customImage.src=image.src;
var imw = customImage.width;
var imh = customImage.height;
var tmp1=0;
var tmp2=0;
var rh;
rh = imh / dimension2;
var rw = imw / dimension;
var ratio = (rw > rh) ? rw : rh;

if (ratio >= 1)
{
tmp1 = imw / ratio;
tmp2 = imh / ratio;
}
else
{
tmp1 = imw;
tmp2 = imh;
}

if (tmp2 rh) ? rw : rh;
if (ratio >= 1)
{
image.width = imw / ratio;
image.height = imh / ratio;
}
else
{
image.width = imw;
image.height = imh;
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s