source: other-projects/nz-flag-design/trunk/design-2d/image-data-to-file.jsp@ 29787

Last change on this file since 29787 was 29787, checked in by davidb, 9 years ago

Changes to support storing on the server side of the HSV histogram calculations

  • Property svn:executable set to *
File size: 2.5 KB
Line 
1<%@ page contentType="text/html; charset=UTF-8" %>
2<!DOCTYPE html>
3<html>
4 <head>
5 </head>
6
7 <body>
8
9 <div style="display: none;">
10
11 <script>
12 // Set up a fallback position in case this page is accessed outside of a JSP context
13 // (i.e., the JSP blocks aren't executed)
14 var message = "Failed to execute JSP code blocks";
15 var exit_val = 404; // not currently used
16
17 </script>
18
19 <%@ page import="java.io.*,java.util.*,java.awt.image.*,javax.imageio.*,javax.xml.bind.DatatypeConverter" %>
20
21 <%!
22
23 void writeImageDataToFile(File image_file, String image_data)
24 {
25 if (image_data == null) {
26 // Some fake data (a small arrow icon) useful for testing purposes when image_data is not supplied in the URL
27 image_data = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABL0lEQVR42q2TLW/DMBCG+1OKworCzMzMAsMCQw0zaGgaahwaXKmsoxuaVD66X3G995Jzk/Rj0rSTXsW+j8cXf+x2/22X7wu1Y0cmVlQEK8IYPsReFiOpjI7CZyFK50gDKx4DtUObQU+LXV9zcifFMHz7o5/ViZBzB0FrsvLoGeDp9HUiNUDgWwq5q98BsUo1+aERLQEK0Zhq1QWIDQNUW4BCNN7Ne7UCuHDT+DHSI3v/eZM4ADidDNjzpOxM1iMAutJ4kzztlwDQDqHM2gIw15jlbmveg1UH2BDbV3xEk5YAjNXvUiWbbbdHiSM5RDsHbQbga6IVwQ8AVkfu3a2U69tP7aEQKqPhYkM2wV9LDDkvbyPoLk3JLV8sCGP4EHtavH1MRbT5MRVz4a+P6S92BSaqyCgd7GKfAAAAAElFTkSuQmCC";
28 }
29 else {
30 // skip over 'data:image/png;base64'
31 image_data = image_data.replace("data:image/png;base64","");
32 }
33
34 byte[] image_bytes = DatatypeConverter.parseBase64Binary(image_data);
35
36 try {
37 FileOutputStream fos = new FileOutputStream(image_file);
38 fos.write(image_bytes);
39 fos.close();
40 }
41 catch (Exception e) {
42 e.printStackTrace();
43 }
44 }
45
46 %>
47
48
49 <%
50 String doc_base = getServletContext().getRealPath("/");
51 File render_dir = new File(doc_base,"render-3d");
52 File render_images_dir = new File(render_dir,"images");
53 File flag_file = new File(render_images_dir,"flag.png");
54
55 String image_data = request.getParameter("imageData");
56
57 String image_filename = request.getParameter("imageFilename");
58 if (image_filename == null) {
59 image_filename = "flag.png";
60 }
61 File full_image_file = new File(render_images_dir,image_filename);
62
63
64 writeImageDataToFile(full_image_file,image_data);
65
66 out.println("<script>");
67 out.println("message = \"Image File Saved: &lt;docBase&gt;/render-3d/images/" + image_filename + "\";");
68 out.println("</script>");
69
70 %>
71
72 </div>
73
74 <script>
75
76 document.write("<div>" + message + "</div>\n");
77
78 </script>
79
80 </body>
81
82</html>
Note: See TracBrowser for help on using the repository browser.