diff --git a/essentials.py b/essentials.py index 6a94138..ddcdccb 100644 --- a/essentials.py +++ b/essentials.py @@ -126,9 +126,9 @@ class ImageCrop: "image": ("IMAGE",), "width": ("INT", { "default": 256, "min": 0, "max": MAX_RESOLUTION, "step": 8, "display": "number" }), "height": ("INT", { "default": 256, "min": 0, "max": MAX_RESOLUTION, "step": 8, "display": "number" }), - "position": (["free", "center", "top-left", "top-center", "top-right", "right-center", "bottom-right", "bottom-center", "bottom-left", "left-center"],), - "x": ("INT", { "default": 0, "min": 0, "step": 1, "display": "number" }), - "y": ("INT", { "default": 0, "min": 0, "step": 1, "display": "number" }), + "position": (["top-left", "top-center", "top-right", "right-center", "bottom-right", "bottom-center", "bottom-left", "left-center", "center"],), + "x_offset": ("INT", { "default": 0, "min": -99999, "step": 1, "display": "number" }), + "y_offset": ("INT", { "default": 0, "min": -99999, "step": 1, "display": "number" }), } } @@ -137,17 +137,12 @@ class ImageCrop: FUNCTION = "execute" CATEGORY = "essentials" - def execute(self, image, width, height, position, x, y): + def execute(self, image, width, height, position, x_offset, y_offset): _, oh, ow, _ = image.shape width = min(ow, width) height = min(oh, height) - - if x+width > ow: - width = ow-x - if y+height > oh: - height = oh-y - + if "center" in position: x = round((ow-width) / 2) y = round((oh-height) / 2) @@ -160,7 +155,22 @@ class ImageCrop: if "right" in position: x = ow-width - image = image[:, y:y+height, x:x+width, :] + x += x_offset + y += y_offset + + x2 = x+width + y2 = y+height + + if x2 > ow: + x2 = ow + if x < 0: + x = 0 + if y2 > oh: + y2 = oh + if y < 0: + y = 0 + + image = image[:, y:y2, x:x2, :] return(image, x, y, ) diff --git a/workflow_all_nodes.json b/workflow_all_nodes.json index 7b2b556..0d2ca31 100644 --- a/workflow_all_nodes.json +++ b/workflow_all_nodes.json @@ -1,6 +1,6 @@ { - "last_node_id": 37, - "last_link_id": 49, + "last_node_id": 40, + "last_link_id": 58, "nodes": [ { "id": 9, @@ -42,7 +42,7 @@ "1": 246 }, "flags": {}, - "order": 22, + "order": 21, "mode": 0, "inputs": [ { @@ -55,31 +55,6 @@ "Node name for S&R": "PreviewImage" } }, - { - "id": 11, - "type": "PreviewImage", - "pos": [ - 1100, - 450 - ], - "size": { - "0": 210, - "1": 246 - }, - "flags": {}, - "order": 19, - "mode": 0, - "inputs": [ - { - "name": "images", - "type": "IMAGE", - "link": 10 - } - ], - "properties": { - "Node name for S&R": "PreviewImage" - } - }, { "id": 12, "type": "PreviewImage", @@ -92,7 +67,7 @@ "1": 246 }, "flags": {}, - "order": 20, + "order": 19, "mode": 0, "inputs": [ { @@ -117,7 +92,7 @@ "1": 246 }, "flags": {}, - "order": 21, + "order": 20, "mode": 0, "inputs": [ { @@ -417,107 +392,6 @@ "Value:" ] }, - { - "id": 7, - "type": "LoadImage", - "pos": [ - -90, - 650 - ], - "size": { - "0": 315, - "1": 314 - }, - "flags": {}, - "order": 1, - "mode": 0, - "outputs": [ - { - "name": "IMAGE", - "type": "IMAGE", - "links": [ - 1, - 4, - 5, - 6, - 8, - 22, - 48 - ], - "shape": 3, - "slot_index": 0 - }, - { - "name": "MASK", - "type": "MASK", - "links": null, - "shape": 3 - } - ], - "properties": { - "Node name for S&R": "LoadImage" - }, - "widgets_values": [ - "venere.jpg", - "image" - ] - }, - { - "id": 3, - "type": "ImageCrop+", - "pos": [ - 430, - 560 - ], - "size": { - "0": 310, - "1": 194 - }, - "flags": {}, - "order": 7, - "mode": 0, - "inputs": [ - { - "name": "image", - "type": "IMAGE", - "link": 5 - } - ], - "outputs": [ - { - "name": "IMAGE", - "type": "IMAGE", - "links": [ - 10 - ], - "shape": 3, - "slot_index": 0 - }, - { - "name": "x", - "type": "INT", - "links": [], - "shape": 3, - "slot_index": 1 - }, - { - "name": "y", - "type": "INT", - "links": null, - "shape": 3 - } - ], - "properties": { - "Node name for S&R": "ImageCrop+" - }, - "widgets_values": [ - 256, - 256, - "free", - 0, - 0 - ] - }, { "id": 2, "type": "ImageResize+", @@ -525,10 +399,10 @@ 430, 340 ], - "size": [ - 310, - 170 - ], + "size": { + "0": 310, + "1": 170 + }, "flags": {}, "order": 6, "mode": 0, @@ -590,7 +464,7 @@ "1": 60 }, "flags": {}, - "order": 8, + "order": 7, "mode": 0, "inputs": [ { @@ -629,7 +503,7 @@ "1": 60 }, "flags": {}, - "order": 9, + "order": 8, "mode": 0, "inputs": [ { @@ -668,7 +542,7 @@ "1": 60 }, "flags": {}, - "order": 10, + "order": 9, "mode": 0, "inputs": [ { @@ -826,7 +700,7 @@ "1": 246 }, "flags": {}, - "order": 23, + "order": 22, "mode": 0, "inputs": [ { @@ -846,12 +720,12 @@ 500, 920 ], - "size": [ - 190, - 30 - ], + "size": { + "0": 190, + "1": 30 + }, "flags": {}, - "order": 11, + "order": 10, "mode": 0, "inputs": [ { @@ -874,6 +748,131 @@ "properties": { "Node name for S&R": "ImageDesaturate+" } + }, + { + "id": 7, + "type": "LoadImage", + "pos": [ + -90, + 650 + ], + "size": { + "0": 315, + "1": 314 + }, + "flags": {}, + "order": 1, + "mode": 0, + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 1, + 4, + 6, + 8, + 22, + 48, + 57 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "MASK", + "type": "MASK", + "links": null, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": [ + "venere.jpg", + "image" + ] + }, + { + "id": 11, + "type": "PreviewImage", + "pos": [ + 1100, + 450 + ], + "size": { + "0": 210, + "1": 246 + }, + "flags": {}, + "order": 23, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 58 + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + } + }, + { + "id": 40, + "type": "ImageCrop+", + "pos": [ + 430, + 560 + ], + "size": [ + 310, + 190 + ], + "flags": {}, + "order": 11, + "mode": 0, + "inputs": [ + { + "name": "image", + "type": "IMAGE", + "link": 57 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 58 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "x", + "type": "INT", + "links": null, + "shape": 3 + }, + { + "name": "y", + "type": "INT", + "links": null, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "ImageCrop+" + }, + "widgets_values": [ + 256, + 256, + "center", + 0, + 0 + ] } ], "links": [ @@ -909,14 +908,6 @@ 0, "IMAGE" ], - [ - 5, - 7, - 0, - 3, - 0, - "IMAGE" - ], [ 6, 7, @@ -941,14 +932,6 @@ 0, "IMAGE" ], - [ - 10, - 3, - 0, - 11, - 0, - "IMAGE" - ], [ 11, 4, @@ -1068,6 +1051,22 @@ 13, 0, "IMAGE" + ], + [ + 57, + 7, + 0, + 40, + 0, + "IMAGE" + ], + [ + 58, + 40, + 0, + 11, + 0, + "IMAGE" ] ], "groups": [],