Home
Knitting
All Knitting
Knitting Needles
Buttons
Knitting Tools
Sock Blockers
Addi Knitting Products
Weaving
All Weaving
Loom Kits
Looms
Loom Tools
Kitchen
Garden
Desktop
Bespoke
{{shopper.order.total_VIEW}}
Order Number: {{shopper.orderNumber}}
Check Out
OpenForum
Giraffe
SaveCanvas
//OpenForum/Giraffe/SaveCanvas/save-canvas.js
if(!OpenForum) { OpenForum = {}; } OpenForum.clipCanvas = function (canvas,x,y,w,h) { var newCanvas = document.createElement('canvas'); newCanvas.width = w; newCanvas.height = h; var newContext = newCanvas.getContext('2d'); newContext.drawImage( canvas, x, y, w, h, 0, 0, w, h ); return newCanvas; }; OpenForum.saveCanvas = function(canvas,targetPageName,fileName,x,y,w,h) { if(x && y && w && h) { canvas = OpenForum.clipCanvas(canvas,x,y,w,h); } var mimeType = "image/png"; var offset = 22; if( fileName.indexOf("jpg")!=-1 || fileName.indexOf("jpeg")!=-1 ) { mimeType = "image/jpeg"; offset = 23; } data = canvas.toDataURL( mimeType, 0.3 ); //data.replaceAll("/+"," "); //data = JSON.stringify(data); OFX.post("/OpenForum/Giraffe/SaveCanvas") .withAction("save") .withData( {pageName: targetPageName, fileName: fileName, data: data} ) .onSuccess( function() { console.log("File " + targetPageName + "/" + fileName + " saved"); }) .go(); }; OpenForum.downloadCanvas = function(canvas, fileName,x,y,w,h) { if(x && y && w && h) { canvas = OpenForum.clipCanvas(canvas,x,y,w,h); } var mimeType = "image/png"; if( fileName.indexOf("jpg")!=-1 || fileName.indexOf("jpeg")!=-1 ) { mimeType = "image/jpeg"; } var hiddenElement = document.createElement('a'); hiddenElement.href = canvas.toDataURL(mimeType); hiddenElement.download = fileName; hiddenElement.style.display = "none"; document.body.appendChild(hiddenElement); hiddenElement.click(); };
//OpenForum/Giraffe/SaveCanvas/post.sjs
var action = transaction.getParameter("action"); if(action===null) { transaction.setResult(transaction.SHOW_PAGE); return; } try{ action = ""+action; result = {result: "error", message: "Action "+action+" not recognised."}; if(action==="save") { var dec = Packages.javax.xml.bind.DatatypeConverter; var data = transaction.getParameter("data"); data = data.substring(data.indexOf(",")+1); data = data.replaceAll(" ","+"); var fileName = transaction.getParameter("fileName"); var pageName = transaction.getParameter("pageName"); var outStream = file.getAttachmentOutputStream(pageName,fileName); outStream.write( Packages.java.util.Base64.getMimeDecoder().decode(data.trim().getBytes("UTF-8")) ); outStream.flush(); outStream.close(); result = {result: "ok", message: "Saved "+pageName+"/"+fileName}; } } catch(e) { transaction.sendJSON( JSON.stringify({result: "error",message: "Error:"+e+" on line "+e.lineNumber+" of "+e.sourceName})); return; } transaction.sendJSON( JSON.stringify(result) );
An error has occurred.
{{OpenForum.errorMessage}}
See technical details
×
Error details.
{{OpenForum.error}}
×
{{OpenForum.alert.title}}
{{OpenForum.alert.message}}
×