pyrit.prompt_converter.AddImageTextConverter#
- class AddImageTextConverter(img_to_add: str, font_name: str | None = 'helvetica.ttf', color: tuple[int, int, int] | None = (0, 0, 0), font_size: int | None = 15, x_pos: int | None = 10, y_pos: int | None = 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 an image file path as an argument to the constructor as opposed to text.
- Parameters:
img_to_add (str) – File path of image to add text to
font_name (str, Optional) – Path of font to use. Must be a TrueType font (.ttf). Defaults to “helvetica.ttf”.
color (tuple, Optional) – Color to print text in, using RGB values. Defaults to (0, 0, 0).
font_size (float, Optional) – Size of font to use. Defaults to 15.
x_pos (int, Optional) – X coordinate to place text in (0 is left most). Defaults to 10.
y_pos (int, Optional) – Y coordinate to place text in (0 is upper most). Defaults to 10.
- __init__(img_to_add: str, font_name: str | None = 'helvetica.ttf', color: tuple[int, int, int] | None = (0, 0, 0), font_size: int | None = 15, x_pos: int | None = 10, y_pos: int | None = 10)[source]#
Methods
__init__
(img_to_add[, font_name, color, ...])convert_async
(*, prompt[, input_type])Converter that overlays input text on the img_to_add.
convert_tokens_async
(*, prompt[, ...])Converts substrings within a prompt that are enclosed by specified start and end tokens.
get_identifier
()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', 'error'] = 'text') ConverterResult [source]#
Converter that overlays input text on the img_to_add.
- Parameters:
prompt (str) – The prompt to be added to the image.
input_type (PromptDataType) – type of data
- Returns:
The filename of the converted image as a ConverterResult Object
- Return type:
- input_supported(input_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error']) bool [source]#
Checks if the input type is supported by the converter
- Parameters:
input_type – 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', 'error']) bool [source]#
Checks if the output type is supported by the converter
- Parameters:
output_type – The output type to check
- Returns:
True if the output type is supported, False otherwise
- Return type: