// JavaScript document
Function previewimage (file, name)
{
VaR maxwidth = 150;
VaR maxheight = 200;
If (file. Files & file. Files [0])
{
VaR IMG = Document. getelementbyid (name );
IMG. onload = function (){
VaR rect = clacimgzoomparam (maxwidth, maxheight, IMG. offsetwidth, IMG. offsetheight );
IMG. width = rect. width;
IMG. Height = rect. height;
IMG. style. marginleft = rect. Left + 'px ';
IMG. style. margintop = rect. Top + 'px ';
}
VaR reader = new filereader ();
Reader. onload = function (EVT) {IMG. src = evt.tar get. Result ;}
Reader. readasdataurl (file. Files [0]);
}
Else
{
VaR sfilter = 'filter: progid: DXImageTransform. Microsoft. alphaimageloader (sizingmethod = scale, src = "';
File. Select ();
VaR src = Document. selection. createRange (). text;
VaR IMG = Document. getelementbyid ('imghead ');
IMG. Filters. Item ('dximagetransform. Microsoft. alphaimageloader '). src = SRC;
VaR rect = clacimgzoomparam (maxwidth, maxheight, IMG. offsetwidth, IMG. offsetheight );
Status = ('rect: '+ rect. Top +', '+ rect. Left +', '+ rect. Width +', '+ rect. Height );
$ ("#" Your name).css ("width", "rect. width "detail .css (" height "," rect. height "2.16.css (" margin-top "," rect. top "detail .css (" margin-left "," rect. left ");
}
}
Function clacimgzoomparam (maxwidth, maxheight, width, height ){
VaR Param = {top: 0, left: 0, width: width, height: height };
If (width> maxwidth | height> maxheight)
{
Ratewidth = width/maxwidth;
Rateheight = height/maxheight;
If (ratewidth> rateheight)
{
Param. width = maxwidth;
Param. Height = math. Round (height/ratewidth );
} Else
{
Param. width = math. Round (width/rateheight );
Param. Height = maxheight;
}
}
Param. Left = math. Round (maxwidth-Param. width)/2 );
Param. Top = math. Round (maxheight-Param. Height)/2 );
Return Param;
}
Local Image Preview