function zipImage (SRC, w, h) {
//start ie 9 mode
Var doc=new ActiveXObject (" htmlfile ");
Doc. Write (" & lt; Meta HTTP - equiv='X - UA - Compatible content=' IE=9/& gt;" );
//load the picture
Var img=doc. The createElement method (" img ");
. Img SRC="C: \ \ Users \ \ Rimifon \ \ Desktop \ " + SRC.
Img. SetAttribute (" crossOrigin ", "anonymous");
//create a canvas
Var CVS=doc. The createElement method (" canvas ");
CVS. Width=w; CVS. Height=h;
Var CTX=CVS. GetContext (" 2 d ");
//the image compression mapping to the specified size
CTX. DrawImage (img, 0, 0, w, h);
Var STR=CVS. ToDataURL (" image/PNG "). Slice (22);
//base64 binary storage
Var=XML doc. The createElement method (" XML ");
XML. LoadXML (" & lt; X/& gt;" );
Var root=XML. DocumentElement;
Root. DataType="bin. Base64";
Root. Text=STR;
Var bin=root. NodeTypedValue;
Var STM=new ActiveXObject (" Adodb. Stream ");
STM. Type=1; STM. The open ();
STM. Write (root. NodeTypedValue);
STM. SaveToFile (" 03. PNG ", 2); STM. The close ();
return str;
}
The WSH. Echo (zipImage (" 02. JPG ", 400, 225));
CodePudding user response:
Test passed, without aspjpeg component, support 2012 and above version of the server, 2008 need to server install ie 9, below is the WSH code examples:& lt; Job> <script language="javascript" & gt;
The WSH. Echo (scaleImage (" home. JPG ", 200, 200));
The function scaleImage (SRC, w, h) {
Var gd=new gd;
Var bin=gd. ScaleImage (SRC, w, h);
Gd. Save (bin, "home. Scaled. PNG");
Return bin;
}
GD () function {
Enclosing newImg=function (SRC) {
STM. Type=1; STM. The open ();
STM. LoadFromFile (SRC);
Var bin=STM. The read ();
STM. The close ();
Root. NodeTypedValue=https://bbs.csdn.net/topics/bin;
Var img=doc. The createElement method (" img ");
. Img SRC="data: image/jpeg. Base64, "+ root. The text;
Img. CrossOrigin="anonymous";
Return img.
};
Enclosing scaleImage=function (SRC, w, h) {
CVS. Width=w; CVS. Height=h;
Var img=this. NewImg (SRC);
Var ss=img. Width/img. Height, ts=w/h;
//contrast ratio of high to width of the original aspect ratio and the present, the former is greater than the latter, based on highly tailored, otherwise the width of the cut out
Var scale=ss & gt; Ts? Img. Height/h: img. Width/w;//zoom ratio
Var sx=(img. Width - w * scale)/2;
Var sy=(img. Height - h * scale)/2;
CTX. DrawImage (img, sx, sy, scale, w * h * scale, 0, 0, w, h);
Root. Text=CVS. ToDataURL (" image/PNG "). Slice (22);
Return a root. NodeTypedValue;
};
This. Save=function (bin, path) {
STM. The open ();
STM. Write (bin);
STM. SaveToFile (path, 2);
STM. The close ();
};
Var doc=new ActiveXObject (" htmlfile ");
Var STM=new ActiveXObject (" Adodb. Stream ");
Var=XML doc. The createElement method (" XML ");
XML. LoadXML (" & lt; X/& gt;" );
Var root=XML. DocumentElement;
Root. DataType="bin. Base64";
//start ie 9 + schema
Doc. Write (" & lt; Meta HTTP - equiv='X - UA - Compatible content=' IE=edge/& gt;" );
//create a canvas
Var CVS=doc. The createElement method (" canvas ");
Var CTX=CVS. GetContext (" 2 d ");
}
</script>
CodePudding user response:
The above code test no problem on the surface of the table, but on a server running asynchronous loading problem encountered images, prompted a blank drawing pictures, so can only temporarily use HTTP asynchronous waiting for ways to deal with this problem:if plete (img.com) return img.you have a better way to welcome guidance
//ASP mode may need to wait the asynchronous image loaded
Var XHR=new ActiveXObject (" MsXml2. ServerXmlHttp ");
while(! Plete img.com {
XHR. Open (" HEAD ", "http://localhost/web.config", true);
xhr.send(); XHR. WaitForResponse ();
}
Return img.