pyrit.prompt_converter.AddTextImageConverter#
- class AddTextImageConverter(text_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
AddImageTextConverter
except we pass in text as an argument to the constructor as opposed to an image file path.- __init__(text_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 text and text properties.
- Parameters:
text_to_add (str) – Text to add to an image. Defaults to empty string.
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
text_to_add
is empty, or iffont_name
does not end with “.ttf”.
Methods
__init__
(text_to_add[, font_name, color, ...])Initializes the converter with the text and text properties.
convert_async
(*, prompt[, input_type])Converts the given prompt (image) by adding text to it.
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'] = 'image_path') ConverterResult [source]#
Converts the given prompt (image) by adding text to it.
- Parameters:
prompt (str) – The image file path to which text will be added.
input_type (PromptDataType) – The type of input data.
- Returns:
The result containing path to the updated image.
- Return type:
- 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:
- 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: