ComfyUI > Nodes > TrentNodes > Just Pad or Crop It

ComfyUI Node: Just Pad or Crop It

Class Name

JustPadOrCropIt

Category
Trent/Image
Author
TrentHunter82 (Account age: 0days)
Extension
TrentNodes
Latest Updated
2026-03-20
Github Stars
0.03K

How to Install TrentNodes

Install this extension via the ComfyUI Manager by searching for TrentNodes
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter TrentNodes in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

Just Pad or Crop It Description

Adjusts image size to match a reference by padding or cropping, preserving central content.

Just Pad or Crop It:

The JustPadOrCropIt node is designed to seamlessly adjust the dimensions of an image to match those of a reference image by either padding or cropping. This node is particularly useful when you need to ensure that your images conform to a specific size requirement without distorting the original content. It intelligently handles each axis of the image independently, adding a solid gray padding to axes that are smaller than the target dimensions and center-cropping axes that are larger. This approach maintains the integrity of the image's central content while ensuring that the final output matches the desired dimensions. The node also generates a binary mask that distinguishes between the original image pixels and the padded regions, which can be particularly useful for inpainting tasks where you need to identify and work with the padded areas separately.

Just Pad or Crop It Input Parameters:

reference

The reference parameter is an image that defines the target dimensions for the operation. It serves as the benchmark for resizing the input image, ensuring that the output matches the height and width of this reference. This parameter is crucial as it dictates the final size of the processed image.

image

The image parameter is the input image that you wish to pad or crop. This image will be adjusted to match the dimensions of the reference image. The operation will either add padding or crop the image, depending on its original size relative to the reference.

gray_value

The gray_value parameter determines the brightness of the padding fill. It is a float value ranging from 0.0 to 1.0, with a default of 0.5. This value controls the shade of gray used for padding, allowing you to customize the appearance of the padded areas to better blend with the original image.

alignment

The alignment parameter specifies where to anchor the source image within the target frame. It offers options such as "center" and "top-left," with "center" being the default. This parameter affects how the image is positioned when cropping is necessary, ensuring that the most important parts of the image are retained.

Just Pad or Crop It Output Parameters:

image

The image output is the processed image that has been padded or cropped to match the dimensions of the reference image. This output ensures that your image fits the desired size requirements while maintaining the integrity of its content.

mask

The mask output is a binary mask that highlights the padded regions of the image. In this mask, a value of 1.0 indicates real pixels from the original image, while a value of 0.0 represents the padded areas. This mask is particularly useful for inpainting tasks, as it allows you to easily identify and manipulate the padded regions.

Just Pad or Crop It Usage Tips:

  • Use the gray_value parameter to adjust the padding color to better match the overall tone of your image, ensuring a more seamless integration of the padded areas.
  • When cropping is necessary, consider using the alignment parameter to control which parts of the image are retained, especially if the central content is not the most important.
  • Utilize the mask output for inpainting tasks to selectively edit or fill in the padded regions without affecting the original content of the image.

Just Pad or Crop It Common Errors and Solutions:

Expected 4D image (B,H,W,C), got <image_dim>D

  • Explanation: This error occurs when the input image does not have the expected four-dimensional shape, which should be in the format of (Batch, Height, Width, Channels).
  • Solution: Ensure that your input image is correctly formatted as a 4D tensor. If necessary, reshape or adjust your image data to meet this requirement before passing it to the node.

No padding happened

  • Explanation: This message indicates that the source image is already larger than or equal to the reference image in both dimensions, so no padding was applied.
  • Solution: If padding is desired, check the dimensions of your reference image and adjust them to be larger than the source image. Alternatively, verify if cropping is the intended operation.

Just Pad or Crop It Related Nodes

Go back to the extension to check out more related nodes.
TrentNodes
RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Models, enabling artists to harness the latest AI tools to create incredible art.

Just Pad or Crop It