1818class AddImageTextConverter (PromptConverter ):
1919 """
2020 Adds a string to an image and wraps the text into multiple lines if necessary.
21- This class is similar to AddImageTextConverter except
22- we pass in an image file path as an argument to the constructor as opposed to text.
2321
24- Args:
25- img_to_add (str): File path of image to add text to
26- font_name (str): Path of font to use. Must be a TrueType font (.ttf). Defaults to "helvetica.ttf".
27- color (tuple): Color to print text in, using RGB values. Defaults to (0, 0, 0).
28- font_size (float): Size of font to use. Defaults to 15.
29- x_pos (int): X coordinate to place text in (0 is left most). Defaults to 10.
30- y_pos (int): Y coordinate to place text in (0 is upper most). Defaults to 10.
22+ This class is similar to :class:`AddTextImageConverter` except
23+ we pass in an image file path as an argument to the constructor as opposed to text.
3124 """
3225
3326 def __init__ (
@@ -39,6 +32,20 @@ def __init__(
3932 x_pos : int = 10 ,
4033 y_pos : int = 10 ,
4134 ):
35+ """
36+ Initializes the converter with the image file path and text properties.
37+
38+ Args:
39+ img_to_add (str): File path of image to add text to.
40+ font_name (str): Path of font to use. Must be a TrueType font (.ttf). Defaults to "helvetica.ttf".
41+ color (tuple): Color to print text in, using RGB values. Defaults to (0, 0, 0).
42+ font_size (float): Size of font to use. Defaults to 15.
43+ x_pos (int): X coordinate to place text in (0 is left most). Defaults to 10.
44+ y_pos (int): Y coordinate to place text in (0 is upper most). Defaults to 10.
45+
46+ Raises:
47+ ValueError: If ``img_to_add`` is empty or invalid, or if ``font_name`` does not end with ".ttf".
48+ """
4249 if not img_to_add :
4350 raise ValueError ("Please provide valid image path" )
4451 if not font_name .endswith (".ttf" ):
@@ -53,11 +60,11 @@ def __init__(
5360
5461 def _load_font (self ):
5562 """
56- Load the font for a given font name and font size
63+ Loads the font for a given font name and font size.
5764
5865 Returns:
59- ImageFont.FreeTypeFont or ImageFont.ImageFont: The loaded font object. If the specified font
60- cannot be loaded, the default font is returned.
66+ ImageFont.FreeTypeFont or ImageFont.ImageFont: The loaded font object. If the specified font
67+ cannot be loaded, the default font is returned.
6168
6269 Raises:
6370 OSError: If the font resource cannot be loaded, a warning is logged and the default font is used instead.
@@ -72,7 +79,7 @@ def _load_font(self):
7279
7380 def _add_text_to_image (self , text : str ) -> Image .Image :
7481 """
75- Adds wrapped text to the image at self._img_to_add.
82+ Adds wrapped text to the image at ` self._img_to_add` .
7683
7784 Args:
7885 text (str): The text to add to the image.
@@ -111,13 +118,17 @@ def _add_text_to_image(self, text: str) -> Image.Image:
111118
112119 async def convert_async (self , * , prompt : str , input_type : PromptDataType = "text" ) -> ConverterResult :
113120 """
114- Converter that overlays input text on the img_to_add .
121+ Converts the given prompt by adding it as text to the image .
115122
116123 Args:
117- prompt (str): The prompt to be added to the image.
118- input_type (PromptDataType): type of data
124+ prompt (str): The text to be added to the image.
125+ input_type (PromptDataType): The type of input data.
126+
119127 Returns:
120- ConverterResult: The filename of the converted image as a ConverterResult Object
128+ ConverterResult: The result containing path to the updated image.
129+
130+ Raises:
131+ ValueError: If the input type is not supported.
121132 """
122133 if not self .input_supported (input_type ):
123134 raise ValueError ("Input type not supported" )
0 commit comments