ComfyUI Extension: Crop To Center
A custom node that crops images to specified dimensions from a center point with optional offset
Custom Nodes (0)
README
Crop To Center
A custom node for ComfyUI that crops images to specified dimensions from a center point with optional offset, removing equal amounts from all sides.
Installation
There are two ways to install this custom node:
ComfyUI Manager (Recommended)
- Install ComfyUI Manager if you don't have it yet.
- Go to
Manager
>Install Custom Nodes
. - Search for
Crop To Center
and clickInstall
. - Restart ComfyUI.
Manual
- Navigate to your
ComfyUI/custom_nodes/
directory. - Clone the repository:
git clone https://github.com/leewinder/comfyui-crop-to-center.git
. - Restart ComfyUI.
Usage
The Crop To Center
node takes an input image and crops it to specified dimensions from the center of the image, with the option to offset the center point to move the crop region around the image.
It removes equal amounts from all sides around the center point, while staying true to the request image dimensions.
<img width="1024" height="1024" alt="Crop Overview" src="https://github.com/user-attachments/assets/0f928ef7-4180-4b3f-a30b-1aecc0408831" />The center offset can move to the edges of the image, but the crop process will prioritise the image dimensions requested, while staying as close to the center point as possible, ensuring your image is always the correct size.
<img width="2074" height="1024" alt="Crop Edges" src="https://github.com/user-attachments/assets/079c6353-6472-495b-a5b4-721d593d623a" />Parameters
<img width="298" height="190" alt="params" src="https://github.com/user-attachments/assets/fbf3091f-f5f2-477c-a1d8-28234e6696c9" />- image: Input image to be cropped
- target_width: Target width for the cropped image (must be less than or equal to source width)
- target_height: Target height for the cropped image (must be less than or equal to source height)
- center_offset_x: Horizontal offset from the true center (positive = right, negative = left)
- center_offset_y: Vertical offset from the true center (positive = up, negative = down)
Outputs
- cropped_image: The cropped image with the specified dimensions
Contributing
Contributions are welcome! Please feel free to submit a Pull Request of if you have any ideas of bugs, please raise an issue.
Contribution Workflow
- Fork this repository
- Make your changes
- Test your changes
- Run quality checks
- Create a Pull Request
Development Setup
Prerequisites
- python 3.9+
- pytest 8.4+
- pylint 3.0+
Setting Up Your Development Environment
- Install pyenv:
# macOS
brew install pyenv
# Or follow the official installation guide:
# https://github.com/pyenv/pyenv#installation
- Clone the repository:
git clone [email protected]:leewinder/comfyui-crop-to-center.git
cd comfyui-crop-to-center
- Set up Python environment:
# Create the virtual environment
pyenv local 3.11.10
python -m venv venv
source venv/bin/activate
- Install dependencies:
# Install the project and development dependencies
pip install -e ".[dev]"
Running Tests
# Run all tests
pytest test/test_crop.py -v
Code Quality
# Run pylint for code quality checks
pylint src/
pylint test/
License
This project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International license.