Skip to content

Commit

Permalink
Update ImageSmartCrop.py
Browse files Browse the repository at this point in the history
  • Loading branch information
turkyden authored Sep 24, 2024
1 parent 77ecb20 commit 99f2237
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions ImageSmartCrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def INPUT_TYPES(s):
return {
"required": {
"image": ("IMAGE",),
"stroke_width": ("INT", {
"width": ("INT", {
"default": 1024,
"min": 0, #Minimum value
"max": 2048, #Maximum value
"step": 1, #Slider's step
"display": "number" # Cosmetic only: display as "number" or "slider"
}),
"stroke_height": ("INT", {
"height": ("INT", {
"default": 1024,
"min": 0, #Minimum value
"max": 2048, #Maximum value
Expand All @@ -43,16 +43,19 @@ def INPUT_TYPES(s):
RETURN_NAMES = ("image",)
FUNCTION = "imageSmartCrop"

def imageSmartCrop(self, image, stroke_width, stroke_height):
def imageSmartCrop(self, image, width, height):
cropper = SmartCrop()
image = tensor2pil(image)
result = cropper.crop(image, stroke_width, stroke_height)
result = cropper.crop(image, width, height)
box = (
result['top_crop']['x'],
result['top_crop']['y'],
result['top_crop']['width'] + result['top_crop']['x'],
result['top_crop']['height'] + result['top_crop']['y']
)
cropped_image = image.crop(box)
cropped_image.thumbnail((width, height), Image.Resampling.LANCZOS)
# cropped_image.save(options.outputfile, 'JPEG', quality=90)

image_tensor = pil2tensor(cropped_image)
return (image_tensor,)
return (image_tensor,)

0 comments on commit 99f2237

Please sign in to comment.