%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.io.*,java.util.*,java.awt.image.*,javax.imageio.*,javax.xml.bind.DatatypeConverter" %>
<%!
void writeImageDataToFile(File image_file, String image_data)
{
if (image_data == null) {
// Some fake data (a small arrow icon) useful for testing purposes when image_data is not supplied in the URL
image_data = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABL0lEQVR42q2TLW/DMBCG+1OKworCzMzMAsMCQw0zaGgaahwaXKmsoxuaVD66X3G995Jzk/Rj0rSTXsW+j8cXf+x2/22X7wu1Y0cmVlQEK8IYPsReFiOpjI7CZyFK50gDKx4DtUObQU+LXV9zcifFMHz7o5/ViZBzB0FrsvLoGeDp9HUiNUDgWwq5q98BsUo1+aERLQEK0Zhq1QWIDQNUW4BCNN7Ne7UCuHDT+DHSI3v/eZM4ADidDNjzpOxM1iMAutJ4kzztlwDQDqHM2gIw15jlbmveg1UH2BDbV3xEk5YAjNXvUiWbbbdHiSM5RDsHbQbga6IVwQ8AVkfu3a2U69tP7aEQKqPhYkM2wV9LDDkvbyPoLk3JLV8sCGP4EHtavH1MRbT5MRVz4a+P6S92BSaqyCgd7GKfAAAAAElFTkSuQmCC";
}
else {
// skip over 'data:image/png;base64'
image_data = image_data.replace("data:image/png;base64","");
}
byte[] image_bytes = DatatypeConverter.parseBase64Binary(image_data);
try {
FileOutputStream fos = new FileOutputStream(image_file);
fos.write(image_bytes);
fos.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
%>
<%
String doc_base = getServletContext().getRealPath("/");
File render_dir = new File(doc_base,"render-3d");
File render_images_dir = new File(render_dir,"images");
File flag_file = new File(render_images_dir,"flag.png");
String image_data = request.getParameter("imageData");
String image_filename = request.getParameter("imageFilename");
if (image_filename == null) {
image_filename = "flag.png";
}
File full_image_file = new File(render_images_dir,image_filename);
writeImageDataToFile(full_image_file,image_data);
out.println("");
%>