Canvas module

Canvas module is for image manipulation purposes.

You can generate image for your styles on fly. It gives you unlimited possibilities to create graphics that matches your theme colors or styles. And it is all inside you *.tea file.

teacss.Canvas is javascript api for image creation and adjustment. It has no dependecies with teacss.core, but is inteded to be used inside tea files.

Under the hood

  • teacss.Canvas relies on HTML5 Canvas, so it will work only with Canvas-enabled browsers.
  • Library uses both 'webgl' and '2d' contexts with seamless switching between the two.
  • Canvas functions work in a different way when is used. You can save created or altered images to disk if needed for production use. li As HTML5 canvas and webgl available only in browser you have to fire build event from client side.
  • TeaCSS comes bundled with several server backend versions. But it is very easy to write an own one. The only thing needed - is to get data from browser and save it to disk. Already compiled and minified.

Simple example

var canvas = new Canvas('foo.jpg')
    .draw2D(function(ctx,c2d) {
        ctx.strokeWidth = 5;

Code is pretty self-explanatory. First, we load 'foo.jpg' adjust brightness and contrast, then colorize it with red and later add some drawings on top.

Then we use it as element background and point that we want to save that image as 'foo_bg.png' if we are in production.

Live sample (simple background generator), FF & Chrome only

Use colorpickers on the right to generate background image.

You can review the full code behind the link (with teacss.ui code):canvas_demo.tea

And here is all the tea code needed for this sample.

body {
    // pretty clear here, huh?
    var canvas = new Canvas("src.png");
    canvas.replaceColors( {
    // display

Sorry, no Opera and no IE for this sample. WebGL has to be enabled.