From d46747be1337fe49b32d4a5a9160bc51a819a7f1 Mon Sep 17 00:00:00 2001 From: Kyle <41976328+ImKyle4815@users.noreply.github.com> Date: Wed, 7 Nov 2018 16:14:04 -0800 Subject: [PATCH] test --- data/scripts/mask.js | 48 +++++++++++++++++++++++--------------------- index.html | 3 +++ 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/data/scripts/mask.js b/data/scripts/mask.js index 91f30075..fa0212e2 100644 --- a/data/scripts/mask.js +++ b/data/scripts/mask.js @@ -2,27 +2,29 @@ var mask = document.createElement("canvas") var maskContext = mask.getContext("2d") function drawMask(img, x, y, width, height, targetContext, imgMask, secondMask, arg) { - var context = targetContext - mask.width = width - mask.height = height - maskContext.clearRect(0, 0, width, height) - maskContext.globalCompositeOperation = "source-over" - if (secondMask.src != undefined) { - maskContext.drawImage(secondMask, 0, 0, width, height) - if (arg == "reverseSecond") { - maskContext.globalCompositeOperation = "source-out" - } else { - maskContext.globalCompositeOperation = "source-in" - } - } - console.log(width + ", " + height + " --- " + imgMask.width + ", " + imgMask.height + " --- " + img.width + ", " + img.height) - maskContext.drawImage(imgMask, 0, 0, width, height) - maskContext.globalCompositeOperation = "source-in" - if (img.src == undefined) { - maskContext.fillStyle = img - maskContext.fillRect(0, 0, width, height) - } else { - maskContext.drawImage(img, 0, 0, width, height) - } - targetContext.drawImage(mask, x, y, width, height) + if (imgMask.width > 0) { + var context = targetContext + mask.width = width + mask.height = height + maskContext.clearRect(0, 0, width, height) + maskContext.globalCompositeOperation = "source-over" + if (secondMask.src != undefined && secondMask.width > 0) { + maskContext.drawImage(secondMask, 0, 0, width, height) + if (arg == "reverseSecond") { + maskContext.globalCompositeOperation = "source-out" + } else { + maskContext.globalCompositeOperation = "source-in" + } + } + //console.log(width + ", " + height + " --- " + imgMask.width + ", " + imgMask.height + " --- " + img.width + ", " + img.height) + maskContext.drawImage(imgMask, 0, 0, width, height) + maskContext.globalCompositeOperation = "source-in" + if (img.src == undefined) { + maskContext.fillStyle = img + maskContext.fillRect(0, 0, width, height) + } else if (img.width > 0) { + maskContext.drawImage(img, 0, 0, width, height) + } + targetContext.drawImage(mask, x, y, width, height) + } } diff --git a/index.html b/index.html index f7d4f05d..9b9aecde 100644 --- a/index.html +++ b/index.html @@ -528,6 +528,9 @@ a:active {