Right now im using sailsjs + Canvas, Im trying to send a canvas created in backend, to the browser into a view.
What i have done so far is creating a canvas in a controller and when you go to a route ex. /canvas it will show the image there. But how would i do if i want to send the canvas into a view? ex. homepage.ejs i understand that the backend dont have the html or document but could you not be able to send the element into a existing view?
I have tried looking at node-canvas browser.js example to make a script on the html to catch the canvas. but i could not make that work. So i need some help now.
CanvasController
module.exports = {
myCanvasAction: function(req, res) {
var { createCanvas } = require('canvas')
var canvas = createCanvas(320, 320)
var ctx = canvas.getContext('2d')
ctx.fillStyle = 'green';
ctx.fillRect(10, 10, 150, 100);
res.set('Content-Type', 'image/png'),
canvas.pngStream().pipe(res);
}
};
Route
'GET /canvas': {
controller: 'Canvas',
action: 'myCanvasAction'
}