pyrit.prompt_converter.AddImageTextConverter#

class AddImageTextConverter(img_to_add: str, font_name: str = 'helvetica.ttf', color: tuple[int, int, int] = (0, 0, 0), font_size: int = 15, x_pos: int = 10, y_pos: int = 10)[source]#

Bases: PromptConverter

Adds a string to an image and wraps the text into multiple lines if necessary.

This class is similar to AddTextImageConverter except we pass in an image file path as an argument to the constructor as opposed to text.

__init__(img_to_add: str, font_name: str = 'helvetica.ttf', color: tuple[int, int, int] = (0, 0, 0), font_size: int = 15, x_pos: int = 10, y_pos: int = 10)[source]#

Initializes the converter with the image file path and text properties.

Parameters:
  • img_to_add (str) – File path of image to add text to.

  • font_name (str) – Path of font to use. Must be a TrueType font (.ttf). Defaults to “helvetica.ttf”.

  • color (tuple) – Color to print text in, using RGB values. Defaults to (0, 0, 0).

  • font_size (float) – Size of font to use. Defaults to 15.

  • x_pos (int) – X coordinate to place text in (0 is left most). Defaults to 10.

  • y_pos (int) – Y coordinate to place text in (0 is upper most). Defaults to 10.

Raises:

ValueError – If img_to_add is empty or invalid, or if font_name does not end with “.ttf”.

Methods

__init__(img_to_add[, font_name, color, ...])

Initializes the converter with the image file path and text properties.

convert_async(*, prompt[, input_type])

Converts the given prompt by adding it as text to the image.

convert_tokens_async(*, prompt[, ...])

Converts substrings within a prompt that are enclosed by specified start and end tokens.

get_identifier()

Returns an identifier dictionary for the converter.

input_supported(input_type)

Checks if the input type is supported by the converter.

output_supported(output_type)

Checks if the output type is supported by the converter.

Attributes

supported_input_types

Returns a list of supported input types for the converter.

supported_output_types

Returns a list of supported output types for the converter.

async convert_async(*, prompt: str, input_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'reasoning', 'error'] = 'text') ConverterResult[source]#

Converts the given prompt by adding it as text to the image.

Parameters:
  • prompt (str) – The text to be added to the image.

  • input_type (PromptDataType) – The type of input data.

Returns:

The result containing path to the updated image.

Return type:

ConverterResult

Raises:

ValueError – If the input type is not supported.

input_supported(input_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'reasoning', 'error']) bool[source]#

Checks if the input type is supported by the converter.

Parameters:

input_type (PromptDataType) – The input type to check.

Returns:

True if the input type is supported, False otherwise.

Return type:

bool

output_supported(output_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'reasoning', 'error']) bool[source]#

Checks if the output type is supported by the converter.

Parameters:

output_type (PromptDataType) – The output type to check.

Returns:

True if the output type is supported, False otherwise.

Return type:

bool