modify p.Image function with following code:
p.image = function image(img, x, y, w, h, dx, dy, dw, dh) {
if (img.width > 0) {
var obj = img.toImageData();
if (img._mask) {
var j, size;
if (img._mask instanceof PImage) {
var objMask = img._mask.toImageData();
for (j = 2, size = img.width * img.height * 4; j < size; j += 4) {
// using it as an alpha channel
obj.data[j + 1] = objMask.data[j];
// but only the blue color channel
}
} else {
for (j = 0, size = img._mask.length; j < size; ++j) {
obj.data[(j << 2) + 3] = img._mask[j];
}
}
}
// draw the image
curTint(obj);
if (arguments.length === 9) {
curContext.drawImage(getCanvasData(obj).canvas, x, y, w, h, dx, dy, dw, dh);
}
else {
var bounds = imageModeConvert(x || 0, y || 0, w || img.width, h || img.height, arguments.length < 4);
curContext.drawImage(getCanvasData(obj).canvas, 0, 0, img.width, img.height, bounds.x, bounds.y, bounds.w, bounds.h);
}
}
};