Nodes Browser

ComfyDeploy: How Face Cropper Node (2:3 Ratio) works in ComfyUI?

What is Face Cropper Node (2:3 Ratio)?

The Face Cropper Node (MarwanFaceCropping) is a custom image processing node designed for ComfyUI. It takes an input image and crops it to a 2:3 aspect ratio, ensuring that most of the subject remains in the frame while maintaining the correct proportions.

How to install it in ComfyDeploy?

Head over to the machine page

  1. Click on the "Create a new machine" button
  2. Select the Edit build steps
  3. Add a new step -> Custom Node
  4. Search for Face Cropper Node (2:3 Ratio) and select it
  5. Close the build step dialig and then click on the "Save" button to rebuild the machine

Face Cropper Node (2:3 Ratio)

Overview

The Face Cropper Node (MarwanFaceCropping) is a custom image processing node designed for ComfyUI. It takes an input image and crops it to a 2:3 aspect ratio, ensuring that most of the subject remains in the frame while maintaining the correct proportions.

Features

  • Automatically crops images to a 2:3 ratio.
  • Maintains the maximum possible height while adjusting width.
  • Handles various image sizes and shapes, including non-square images.
  • Includes error handling for incorrect input shapes.

Installation

  1. Clone this repository:
    git clone https://github.com/marawan206/ComfyUI-FaceCropper.git
    cd face-cropper-node
    
  2. Install dependencies if needed:
    pip install torch pytest
    
  3. Add the node to your ComfyUI workflow.

Usage

The node expects an input image tensor of shape (batch, height, width, channels), where:

  • batch is the number of images.
  • height remains unchanged.
  • width is adjusted to maintain a 2:3 ratio.

Example:

import torch
from face_cropper_node import MarwanFaceCropping

image = torch.rand(1, 1024, 1024, 3)  # Example input image
node = MarwanFaceCropping()
cropped, = node.execute(image)
print(cropped.shape)  # Output shape should be (1, 1024, 682, 3)

Running Tests

To verify functionality, run:

pytest test.py

Contributing

Feel free to submit issues or pull requests to improve the node.

License

MIT License. See LICENSE for details.