Skip to content

Instantly share code, notes, and snippets.

// c is an object like {:cnvs <cnvs> :ctx <ctx>}
function canvasTrim(c, o={}) {
if(isEmpty(o)){o.top = o.left = o.right = o.bottom = true;}
var w = c.cnvs.width,
h = c.cnvs.height,
ctx = c.ctx,
padding = 2, // Padding around trim
imageData = ctx.getImageData(0, 0, w, h), // Get Pixel Data
alpha = [],