image_modifier.add_frame

Module Contents

Functions

add_pad(image[, border_size])

Adds padding to all sides of an image.

make_borders_colored(image[, border_size, color_name])

Adds a colored border to all sides of an image. This function now supports both RGB and RGBA images.

add_frame(image[, border_size, color_name, overlay])

Adds a frame to an image either by overlaying a colored border or by first padding the image and

image_modifier.add_frame.add_pad(image, border_size=30)[source]

Adds padding to all sides of an image.

This function applies a uniform padding around the image. The padding is added to the top, bottom, left, and right sides of the image. The added padding is black by default.

Parameters: image (numpy.ndarray): The input image to which padding will be added.

It should be a 3-dimensional array representing an RGB image.

border_size (int, optional): The size of the padding to be added to each side of the image.

Defaults to 30.

Returns: numpy.ndarray: The padded image. The size of the output image will be increased by

2 * border_size in both height and width.

Note: The padding is only added to the spatial dimensions (height and width) of the image. The depth (color channels) of the image remains unaltered.

Example usage: padded_image = add_pad(original_image, border_size=50)

image_modifier.add_frame.make_borders_colored(image, border_size=30, color_name='red')[source]

Adds a colored border to all sides of an image. This function now supports both RGB and RGBA images.

Parameters: image (numpy.ndarray): The input image to which the border will be added.

It should be a 3-dimensional array representing an RGB or RGBA image.

border_size (int, optional): The thickness of the border to be added to each side of the image.

Defaults to 30 pixels.

color_name (str or tuple, optional): The color of the border. This can be a predefined color name

(‘red’, ‘green’, ‘blue’, ‘yellow’, ‘black’, ‘white’) or an RGB/RGBA tuple. Defaults to ‘red’.

Returns: numpy.ndarray: The image with the colored border added. The size of the output image remains unchanged.

Raises: ValueError: If the border size is too large for the given image dimensions or if the provided color name

is not valid.

image_modifier.add_frame.add_frame(image, border_size=30, color_name='red', overlay=True)[source]

Adds a frame to an image either by overlaying a colored border or by first padding the image and then adding a colored border. The function supports both RGB images and PNG images with alpha channels.

If ‘overlay’ is set to True, the function overlays a colored border on the image without changing its size. If ‘overlay’ is False, the function first adds padding (increasing the image size) and then applies the colored border.

Parameters: image (numpy.ndarray): The input image to which the frame will be added.

It should be a 3 or 4-dimensional array.

border_size (int, optional): The thickness of the border/frame to be added. Defaults to 100 pixels. color_name (str or tuple, optional): The color of the border/frame. Can be a predefined color name

(like ‘red’, ‘green’, ‘blue’, etc.) or an RGB tuple. Defaults to ‘red’.

overlay (bool, optional): A flag to determine if the border should be overlaid on the existing image (True)

or if the image should be first padded (False). Defaults to True.

Returns: numpy.ndarray: The image with the added frame. The size of the output image depends on the ‘overlay’ flag.

Raises: ValueError: If the input image is grayscale or if the color name is invalid.

Example usage: framed_image_overlay = add_frame(original_image, border_size=50, color_name=’blue’, overlay=True) framed_image_padded = add_frame(original_image, border_size=50, color_name=’green’, overlay=False)