diff --git a/core/src/processing/core/PImage.java b/core/src/processing/core/PImage.java index 93a1641e1..2f350775c 100644 --- a/core/src/processing/core/PImage.java +++ b/core/src/processing/core/PImage.java @@ -866,6 +866,14 @@ public class PImage implements PConstants, Cloneable { */ public void mask(PImage img) { img.loadPixels(); + if (this.pixelWidth != img.pixelWidth || this.pixelHeight != img.pixelHeight) { + if (this.pixelDensity != img.pixelDensity) { + throw new IllegalArgumentException("mask() requires the mask image to have the same pixel size after adjusting for pixelDensity."); + } + else if (this.width != img.width || this.height != img.height) { + throw new IllegalArgumentException("mask() requires the mask image to have the same width and height."); + } + } mask(img.pixels); }