简体   繁体   中英

How to draw a graphic object like a circle or a rectangle in google functions?

I am trying to learn how to work with google functions and I want to be able to implement graphics in google functions. I want to be able to draw simple shapes like rectangle, ellipse and a line. Is it possible if so how? This is something I have tried and it is not working:

 /** * HTTP Cloud Function. * This function is exported by index.js, and is executed when * you make an HTTP request to the deployed function's endpoint. * * @param {Object} req Cloud Function request context. * More info: https://expressjs.com/en/api.html#req * @param {Object} res Cloud Function response context. * More info: https://expressjs.com/en/api.html#res */ var PImage = require('pureimage'); var img1 = PImage.make(100, 50); exports.helloGET = (req, res) => { res.send(" " + (2 * 234) + " " + Test(34) + TestDraw()); }; function TestDraw() { var ctx = img1.getContext('2d'); ctx.fillStyle = 'rgba(255,0,0, 0.5)'; ctx.fillRect(0, 0, 100, 100); return false; } function Test(x) { if (x < 0) { return 1; } return x * x * Test(x - 4); }

^ this code is supposed to draw a rectangle and output some numbers. I am just getting the numbers and no rectangle is being drawn. It would be very helpful if there is some library that can be used to draw stuff using google functions.

I think that Cloud Functions are rather to compute some value, than to draw on front end. I'm not sure if its even possible (probably is, but will be difficult). In this situation I suppose you see 'false' at the end of the value shown in brawser as this is what you are adding at the end of response ( + TestDraw() will return false converted to string by + operator)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM