Load mask from file

This commit is contained in:
cmdr2 2023-03-11 12:37:51 +05:30
parent 5dd92b1d3f
commit bb0f7cd1cd
2 changed files with 46 additions and 0 deletions

View File

@ -214,3 +214,10 @@
.image-editor-popup h4 { .image-editor-popup h4 {
text-align: left; text-align: left;
} }
.image-editor-popup .load_mask {
display: none;
}
.inpainter .load_mask {
display: flex;
}

View File

@ -117,6 +117,42 @@ const IMAGE_EDITOR_TOOLS = [
] ]
const IMAGE_EDITOR_ACTIONS = [ const IMAGE_EDITOR_ACTIONS = [
{
id: "load_mask",
name: "Load mask from file",
className: "load_mask",
icon: "fa-regular fa-folder-open",
handler: (editor) => {
let el = document.createElement('input')
el.setAttribute("type", "file")
el.addEventListener("change", function() {
if (this.files.length === 0) {
return
}
let reader = new FileReader()
let file = this.files[0]
reader.addEventListener('load', function(event) {
let maskData = reader.result
editor.layers.drawing.ctx.clearRect(0, 0, editor.width, editor.height)
var image = new Image()
image.onload = () => {
editor.layers.drawing.ctx.drawImage(image, 0, 0, editor.width, editor.height)
}
image.src = maskData
})
if (file) {
reader.readAsDataURL(file)
}
})
el.click()
},
trackHistory: true
},
{ {
id: "fill_all", id: "fill_all",
name: "Fill all", name: "Fill all",
@ -457,6 +493,9 @@ class ImageEditor {
var element = document.createElement("div") var element = document.createElement("div")
var icon = document.createElement("i") var icon = document.createElement("i")
element.className = "image-editor-button button" element.className = "image-editor-button button"
if (action.className) {
element.className += " " + action.className
}
icon.className = action.icon icon.className = action.icon
element.appendChild(icon) element.appendChild(icon)
element.append(action.name) element.append(action.name)