diff --git a/lib/page.js b/lib/page.js index d71cc0d6..98adf358 100644 --- a/lib/page.js +++ b/lib/page.js @@ -301,4 +301,11 @@ Volcanos("page", { requireDraw: function(can, cb) { can.require(["/plugin/local/wiki/draw.js", "/plugin/local/wiki/draw/path.js"], function() { can.onimport._last_init(can, can.request(), can._output), can.onappend.style(can, wiki.DRAW, can._fields), cb() }) }, + drawText: function(can, text, size, margin) { text = text.slice(0, 1), size = size||80, margin = margin||10 + var colors = ["rgb(239,150,26)", 'rgb(255,58,201)', "rgb(111,75,255)", "rgb(36,174,34)", "rgb(80,80,80)"] + var canvas = can.page.Create(can, html.CANVAS, {width: size, height: size}), ctx = canvas.getContext("2d") + ctx.fillStyle = can.base.isIn(can.getHeaderTheme(), html.DARK, chat.BLACK)? cli.BLACK: cli.WHITE, ctx.fillRect(0, 0, size, size), ctx.fillStyle = colors[Math.floor(Math.random()*(colors.length))], ctx.fillRect(margin, margin, size-2*margin, size-2*margin) + ctx.fillStyle = cli.WHITE, ctx.font = (size/text.length-30)+"px Arial", ctx.textAlign = "center", ctx.textBaseline = "middle", ctx.fillText(text, size/2, size/2) + return canvas.toDataURL(nfs.IMAGE_JPEG, 1) + }, }) diff --git a/proto.js b/proto.js index c8443a0a..02e994f7 100644 --- a/proto.js +++ b/proto.js @@ -128,6 +128,8 @@ var nfs = { _CSS: ".css", _JS: ".js", DF: ice.DF, PS: ice.PS, PT: ice.PT, PWD: "./", SRC: "src/", + + IMAGE_JPEG: "image/jpeg", } var cli = { PWD: "pwd", SYSTEM: "system", DAEMON: "daemon", ORDER: "order", BUILD: "build",