From http://jsfiddle.net/fabricjs/URWru/