Skip to content

Instantly share code, notes, and snippets.

@liana-p
Created November 13, 2018 16:09
Show Gist options
  • Select an option

  • Save liana-p/0ea3827940d588cd91bb983211bff3c8 to your computer and use it in GitHub Desktop.

Select an option

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
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