Skip to content

Commit 84d4d0c

Browse files
committed
account for pixel density in image mask
1 parent 304ee90 commit 84d4d0c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/image/p5.Image.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -878,21 +878,22 @@ p5.Image = class {
878878
}
879879
const currBlend = this.drawingContext.globalCompositeOperation;
880880

881-
let scaleFactor = 1;
881+
let imgScaleFactor = this._pixelDensity;
882+
let maskScaleFactor = 1;
882883
if (p5Image instanceof p5.Renderer) {
883-
scaleFactor = p5Image._pInst._pixelDensity;
884+
maskScaleFactor = p5Image._pInst._pixelDensity;
884885
}
885886

886887
const copyArgs = [
887888
p5Image,
888889
0,
889890
0,
890-
scaleFactor * p5Image.width,
891-
scaleFactor * p5Image.height,
891+
maskScaleFactor * p5Image.width,
892+
maskScaleFactor * p5Image.height,
892893
0,
893894
0,
894-
this.width,
895-
this.height
895+
imgScaleFactor * this.width,
896+
imgScaleFactor * this.height
896897
];
897898

898899
this.drawingContext.globalCompositeOperation = 'destination-in';
@@ -907,8 +908,8 @@ p5.Image = class {
907908
this.gifProperties.frames[i].image = this.drawingContext.getImageData(
908909
0,
909910
0,
910-
this.width,
911-
this.height
911+
imgScaleFactor * this.width,
912+
imgScaleFactor * this.height
912913
);
913914
}
914915
this.drawingContext.putImageData(

0 commit comments

Comments
 (0)