This page is work-in-progress. You can reach me on twitter or mail to rezoner1337@gmail.com

trim

Autocrop layer to its contents.

/* trim transparent color */

cq().trim(); 

/* trim using provided color as transparent */

cq().trim(color); 

Trim in action

var layer = cq(200, 200);

layer.clear("#111");
layer.fillStyle("#fff").fillRect(32, 32, 64, 64);

layer.appendTo(document.body)

layer.clone().trim("#111").appendTo(document.body);

Getting changes

This code will save changes to provided object.

var changes = {};
cq.trim(color, changes);

How many pixels has been cut off by each side:

changes { 
  top:     Number,
  right:   Number,
  bottom:  Number,
  left:    Number 
}


Have any questions? Don't hesitate to ask:

Post issues on github, support my work on gratipay author rezoner