<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Page language = "java" import = "java. util. *" %>
<% @ Page language = "java" import = "java. io. *" %>
<% @ Page language = "java" import = "java. awt. *" %>
<% @ Page language = "java" import = "java. awt. image. *" %>
<% @ Page language = "java" import = "com.sun.image.codec.jpeg. *" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xml (standardization is getting closer and closer) ns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
<Meta name = "generator" content = "editplus"/>
<Meta name = "author" content = "Wang Shiqiang"/>
<Meta name = "keywords" content = "Wang Shiqiang"/>
<Meta name = "description" content = ""/>
</Head>
<Body>
<%
Response. setContentType ("text/html; charset = gb2312 ");
Request. setCharacterEncoding ("gb2312 ");
Out. print ("========================== Test for thumbtail picture ================ ");
// ----------------------- After the upload is complete, the thumbnail is generated -------------------------
Java. io. File file = new java. io. File ("E: \ 1110168154_58348.jpg"); // saveurl); // read the uploaded File
String newurl = "E: \ 1110168154_58348_min.jpg"; // request. getRealPath ("/") + url + filename + "_ min." + ext; // new thumbnail save address
Image src = javax. imageio. ImageIO. read (file); // construct an Image object
Float tagsize = 287;
Int old_w = src. getWidth (null); // obtain the source image width.
Int old_h = src. getHeight (null );
Int new_w = 0;
Int new_h = 0; // obtain the source image length.
Int tempsize;
Out. print ("<br/> the old width is:" + old_w + "the old height is" + old_h + "<br/> ");
Float tempdouble;
If (old_w> old_h ){
Tempdouble = old_w/tagsize;
} Else {
Tempdouble = old_h/tagsize;
}
New_w = Math. round (old_w/tempdouble );
New_h = Math. round (old_h/tempdouble); // calculate the length and width of the new graph.
Out. print ("the new width is:" + new_w + "the new height is" + new_h + "<br/> ");
BufferedImage tag = new BufferedImage (new_w, new_h, BufferedImage. TYPE_INT_RGB );
Tag. getGraphics (). drawImage (src, new_w, new_h, null); // draw the reduced Graph
FileOutputStream newimage = new FileOutputStream (newurl); // output to the file stream
Required imageencoder encoder = required codec. createJPEGEncoder (newimage );
Encoder. encode (tag); // near JPEG encoding
Newimage. close ();
/*
*/
%>
</Body>
</Html>