diff --git a/mikey_nodes.py b/mikey_nodes.py index e4c7592..10bed4a 100644 --- a/mikey_nodes.py +++ b/mikey_nodes.py @@ -470,6 +470,39 @@ class BatchResizeImageSDXL(ResizeImageSDXL): images.append(img) return (images,) +class BatchCropImageSDXL: + @classmethod + def INPUT_TYPES(s): + return {"required": {"image_directory": ("STRING", {"multiline": False, "placeholder": "Image Directory"}), + "crop_amount": ("FLOAT", {"default": 0.5})}} + + RETURN_TYPES = ('IMAGE',) + RETURN_NAMES = ('image',) + FUNCTION = 'batch' + CATEGORY = 'Mikey/Image' + OUTPUT_IS_LIST = (True, ) + + def batch(self, image_directory, crop_amount): + if not os.path.exists(image_directory): + raise Exception(f"Image directory {image_directory} does not exist") + + images = [] + for file in os.listdir(image_directory): + if file.endswith('.png') or file.endswith('.jpg') or file.endswith('.jpeg') or file.endswith('.webp') or file.endswith('.bmp') or file.endswith('.gif'): + img = Image.open(os.path.join(image_directory, file)) + # resize image + width, height = img.size + pixels = int(width * crop_amount) // 8 * 8 + left = pixels + upper = pixels + right = width - pixels + lower = height - pixels + # Crop the image + cropped_img = img.crop((left, upper, right, lower)) + img = pil2tensor(cropped_img) + images.append(img) + return (images,) + def get_save_image_path(filename_prefix, output_dir, image_width=0, image_height=0): def map_filename(filename): try: