Created
November 13, 2018 16:09
-
-
Save liana-p/0ea3827940d588cd91bb983211bff3c8 to your computer and use it in GitHub Desktop.
canvas text wrapped buffer thing using the https://github.com/namniak/canvas-text-wrapper library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function renderToCanvas = function (width, height, renderFunction, canvasParam) { | |
| var buffer = document.createElement('canvas'); | |
| buffer.width = width; | |
| buffer.height = height; | |
| if (canvasParam) { | |
| var ctx = buffer.getContext('2d'); | |
| for (var i in canvasParam) { | |
| ctx[i] = canvasParam[i]; | |
| } | |
| } | |
| renderFunction(buffer); | |
| return buffer; | |
| }; | |
| var renderText = function (canvas) { | |
| CanvasTextWrapper(canvas, text, options); // Look up CanvasTextWrapper options in their doc https://github.com/namniak/canvas-text-wrapper | |
| }; | |
| var buffer = utils.renderToCanvas(width, height, renderText, canvasOptions); // Generates a canvas of the size we want to allow for the text and renders the text in it | |
| // in sharing code | |
| ctx.drawImage(buffer, 100, 100); // Renders generated canvas buffer to our main sharing canvas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment