🍒Image_Square_Pad⬜图片正方形填充:
The Image_Square_Pad node is designed to transform any given image into a square format by padding it with a specified background color or transparency. This node is particularly useful for ensuring uniformity in image dimensions, which is often required in various AI art applications and image processing tasks. By centering the original image within a square canvas, the node maintains the integrity of the original content while adding padding to achieve the desired square shape. This process is non-destructive, meaning the original image content remains unchanged, and only the surrounding area is modified. The node supports both RGB and RGBA images, allowing for transparent padding if needed. This flexibility makes it an essential tool for artists and developers who need to prepare images for further processing or display in a consistent format.
🍒Image_Square_Pad⬜图片正方形填充 Input Parameters:
image
The image parameter is the primary input for the node, representing the image tensor that you wish to pad into a square format. This tensor should include dimensions for batch size, height, width, and channels. The node will analyze these dimensions to determine the necessary padding to achieve a square shape. The image can be in RGB or RGBA format, and the node will handle the addition of an alpha channel if transparency is required. There are no specific minimum or maximum values for this parameter, as it depends on the size and format of the input image.
color
The color parameter allows you to specify the background color used for padding the image. If a color is provided, it will be converted from a hexadecimal format to RGB values and used to fill the padding area. If no color is specified, the node defaults to using transparent padding, which is particularly useful for images that require an alpha channel. This parameter accepts any valid hexadecimal color code, and the default value is transparent (i.e., [0.0, 0.0, 0.0, 0.0] for RGBA images).
alpha
The alpha parameter is optional and is used to provide an alpha channel for the image if it is not already present. This parameter supports various formats, including [H, W], [1, H, W], [B, H, W], and [B, C, H, W]. If provided, the alpha channel will be integrated into the image to create an RGBA format, allowing for transparent padding. The node ensures that the dimensions of the alpha channel match those of the original image, and it can invert the alpha values if specified.
🍒Image_Square_Pad⬜图片正方形填充 Output Parameters:
square_tensor
The square_tensor is the output parameter, representing the padded image in a square format. This tensor maintains the original image content centered within a square canvas, with padding applied as specified by the color and alpha parameters. The output retains the batch size and channel dimensions of the input image, ensuring compatibility with subsequent processing steps. The square tensor is crucial for applications requiring consistent image dimensions, such as machine learning models or artistic compositions.
🍒Image_Square_Pad⬜图片正方形填充 Usage Tips:
- To maintain transparency in your images, ensure that the
alphaparameter is correctly set or that your input image already includes an alpha channel. - Use the
colorparameter to match the padding color with your project's theme or background, especially when transparency is not required. - Consider the aspect ratio of your original image when choosing padding options, as this can affect the visual balance of the final square image.
🍒Image_Square_Pad⬜图片正方形填充 Common Errors and Solutions:
Alpha尺寸与图像尺寸不匹配
- Explanation: This error occurs when the dimensions of the provided alpha channel do not match those of the original image.
- Solution: Ensure that the alpha channel dimensions are identical to the original image dimensions. Adjust the alpha data to match the height and width of the input image.
不支持的alpha维度
- Explanation: This error indicates that the alpha channel provided is in an unsupported format.
- Solution: Verify that the alpha channel is in one of the supported formats:
[H, W],[1, H, W],[B, H, W], or[B, C, H, W]. Adjust the alpha data format accordingly.
