From 0a3a1e740dcc4a2bbe42dc0b451e2ad3d68419fb Mon Sep 17 00:00:00 2001 From: ZXXXX <131333221+Zar4X@users.noreply.github.com> Date: Wed, 25 Jun 2025 22:42:40 +0800 Subject: [PATCH] Add files via upload --- README.md | 90 +++++++++++++++++++++++++++++------------------------ __init__.py | 57 +++++++++++++++++++-------------- 2 files changed, 82 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index 0f77b4c..cde911b 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,61 @@ -# ComfyUI Image Resizing +# ComfyUI Image Resizing *Precision dimension control nodes for aspect ratio adjustments and resizing workflows* ---- - ## Core Features -### 📐 Aspect Ratio Calculations -- `calculate_aspect_ratio_extension` - `►` Computes required pixel extension to match target proportions - `►` Outputs integer value for direct pipeline integration +### 📐 Analysis & Calculation +- `image_aspect_ratio_extractor` - Extract aspect ratios with constraints (0.25-4.0 range) +- `image_resolution_extractor` - Extract specific dimensions (width, height, shortest/longest side) +- `calculate_aspect_ratio_extension` - Compute pixel extensions for target aspect ratios +- `calculate_upscale_factor` - Determine optimal scaling ratios +- `calculate_upscale_rounds` - Calculate iteration count for multi-stage upscaling -### 🔢 Scaling Mathematics -- `calculate_upscale_factor` - `►` Determines optimal scaling ratio between source/target dimensions -- `calculate_upscale_rounds` - `►` Calculates iteration count for multi-stage upscaling (requires IF node) +### 🔧 Resizing & Cropping +- `resize_to_multiple` - Resize images to multiples of specified numbers (stretch/crop) +- `image_crop_by_percentage` - Precision cropping with percentage/pixel controls +- `mask_crop_by_percentage` - Synchronized mask cropping with detection modes +- `extend_canvas_by_percentage` - Expand canvas with color fill and feathering -### 🖌️ Canvas Manipulation -- `extend_canvas_by_percentage` - `►` Expand canvas using % or absolute pixels (`use_pixels` toggle) -- `image_crop_by_percentage` - `►` Precision cropping with %/pixel unit switching -- `mask_crop_by_percentage` - `►` Synchronized mask cropping with identical controls +## Key Features +- **Mathematical Precision** - Pixel-perfect calculations with rounding control +- **Dual Measurement Modes** - Seamless percentage ↔ pixel conversion +- **Non-Destructive Workflow** - All operations preserve source data +- **Advanced Detection** - Mask-based cropping with multiple detection algorithms ---- +## Installation -## Key Advantages -- **Pixel-Perfect Precision** - `▸` Mathematical dimension calculations - `▸` Rounding control for production pipelines - -- **Dual Measurement Modes** - `▸` Seamless percentage ↔ pixel conversion - `▸` Unit toggling without breaking workflows - -- **Non-Destructive Workflow** - `▸` All operations preserve source data - `▸` Chainable outputs for complex transforms +1. Clone to your ComfyUI `custom_nodes` directory: + ``` + ComfyUI/custom_nodes/image-resizing/ + ``` ---- +2. Restart ComfyUI + +## Nodes Overview + +### Analysis Nodes +- **Aspect Ratio Extractor**: Extracts ratios with constraints, supports rounding to common ratios +- **Resolution Extractor**: Extracts width, height, shortest, or longest side dimensions +- **Aspect Ratio Extension**: Calculates pixel extensions needed for target aspect ratios +- **Upscale Factor**: Determines optimal scaling ratios between source/target dimensions +- **Upscale Rounds**: Calculates iteration count for multi-stage upscaling workflows + +### Processing Nodes +- **Resize to Multiple**: Resizes images to multiples of specified numbers (32, 64, etc.) +- **Image Crop by Percentage**: Precision cropping with 9 position options and offset controls +- **Mask Crop by Percentage**: Advanced mask-based cropping with detection algorithms +- **Extend Canvas by Percentage**: Expands canvas with color fill, feathering, and mask support ## Typical Use Cases -Content preparation: -○ Adapt assets for specific aspect ratios -○ Create social media templates -○ Match AI model input requirements +- Adapting assets for specific aspect ratios +- Creating social media templates +- Matching AI model input requirements +- Batch canvas extensions and cropping +- Multi-stage upscale preparations -Production workflows: -○ Batch canvas extensions -○ Multi-stage upscale preparations -○ Mask-accurate image editing +## Requirements +- ComfyUI +- Standard ComfyUI dependencies + +## License +This project is provided as-is for the ComfyUI community. diff --git a/__init__.py b/__init__.py index c2f08fc..951d5cd 100644 --- a/__init__.py +++ b/__init__.py @@ -1,24 +1,33 @@ -from .nodes.image_crop_by_percentage import ImageCropByPercentage -from .nodes.mask_crop_by_percentage import MaskCropByPercentage -from .nodes.extend_canvas_by_percentage import ExtendCanvasByPercentage -from .nodes.calculate_aspect_ratio_extension import CalculateAspectRatioExtension -from .nodes.calculate_upscale_factor import CalculateUpscaleFactor -from .nodes.calculate_upscale_rounds import CalculateUpscaleRounds - -NODE_CLASS_MAPPINGS = { - "ImageCropByPercentage": ImageCropByPercentage, - "MaskCropByPercentage": MaskCropByPercentage, - "ExtendCanvasByPercentage": ExtendCanvasByPercentage, - "CalculateAspectRatioExtension": CalculateAspectRatioExtension, - "CalculateUpscaleFactor": CalculateUpscaleFactor, - "CalculateUpscaleRounds": CalculateUpscaleRounds, -} - -NODE_DISPLAY_NAME_MAPPINGS = { - "ImageCropByPercentage": "Image Crop By Percentage", - "MaskCropByPercentage": "Mask Crop By Percentage", - "ExtendCanvasByPercentage": "Extend Canvas By Percentage", - "CalculateAspectRatioExtension": "Calculate Aspect Ratio Extension", - "CalculateUpscaleFactor": "Calculate Upscale Factor", - "CalculateUpscaleRounds": "Calculate Upscale Rounds", -} +from .nodes.image_crop_by_percentage import ImageCropByPercentage +from .nodes.mask_crop_by_percentage import MaskCropByPercentage +from .nodes.extend_canvas_by_percentage import ExtendCanvasByPercentage +from .nodes.calculate_aspect_ratio_extension import CalculateAspectRatioExtension +from .nodes.calculate_upscale_factor import CalculateUpscaleFactor +from .nodes.calculate_upscale_rounds import CalculateUpscaleRounds +from .nodes.resize_to_multiple import ResizeToMultiple +from .nodes.image_resolution_extractor import ImageResolutionExtractor +from .nodes.image_aspect_ratio_extractor import ImageAspectRatioExtractor + +NODE_CLASS_MAPPINGS = { + "ImageCropByPercentage": ImageCropByPercentage, + "MaskCropByPercentage": MaskCropByPercentage, + "ExtendCanvasByPercentage": ExtendCanvasByPercentage, + "CalculateAspectRatioExtension": CalculateAspectRatioExtension, + "CalculateUpscaleFactor": CalculateUpscaleFactor, + "CalculateUpscaleRounds": CalculateUpscaleRounds, + "ResizeToMultiple": ResizeToMultiple, + "ImageResolutionExtractor": ImageResolutionExtractor, + "ImageAspectRatioExtractor": ImageAspectRatioExtractor, +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "ImageCropByPercentage": "Image Crop By Percentage", + "MaskCropByPercentage": "Mask Crop By Percentage", + "ExtendCanvasByPercentage": "Extend Canvas By Percentage", + "CalculateAspectRatioExtension": "Calculate Aspect Ratio Extension", + "CalculateUpscaleFactor": "Calculate Upscale Factor", + "CalculateUpscaleRounds": "Calculate Upscale Rounds", + "ResizeToMultiple": "Resize To Multiple", + "ImageResolutionExtractor": "Image Resolution Extractor", + "ImageAspectRatioExtractor": "Image Aspect Ratio Extractor", +}