@@ -21,18 +21,18 @@ def generate_from_tuple(cls, t):
2121 cls .generate (* t )
2222
2323 @classmethod
24- def generate (cls , index , text , font , out_dir , height , extension , skewing_angle , random_skew , blur , random_blur , background_type , distorsion_type , distorsion_orientation , is_handwritten , name_format , width , alignment , text_color , orientation , space_width ):
24+ def generate (cls , index , text , font , out_dir , size , extension , skewing_angle , random_skew , blur , random_blur , background_type , distorsion_type , distorsion_orientation , is_handwritten , name_format , width , alignment , text_color , orientation , space_width ):
2525 image = None
2626
2727 ##########################
2828 # Create picture of text #
2929 ##########################
3030 if is_handwritten :
3131 if orientation == 1 :
32- raise Exception ("Vertical handwritten text is unavailable" )
32+ raise ValueError ("Vertical handwritten text is unavailable" )
3333 image = HandwrittenTextGenerator .generate (text )
3434 else :
35- image = ComputerTextGenerator .generate (text , font , text_color , height , orientation , space_width )
35+ image = ComputerTextGenerator .generate (text , font , text_color , size , orientation , space_width )
3636
3737 random_angle = random .randint (0 - skewing_angle , skewing_angle )
3838
@@ -66,23 +66,32 @@ def generate(cls, index, text, font, out_dir, height, extension, skewing_angle,
6666 # Resize image to desired format #
6767 ##################################
6868
69- new_width = int (float (distorted_img .size [0 ] + 10 ) * (float (height ) / float (distorted_img .size [1 ] + 10 )))
70-
71- resized_img = distorted_img .resize ((new_width , height - 10 ), Image .ANTIALIAS )
72-
73- background_width = width if width > 0 else new_width + 10
69+ # Horizontal text
70+ if orientation == 0 :
71+ new_width = int (float (distorted_img .size [0 ] + 10 ) * (float (size ) / float (distorted_img .size [1 ] + 10 )))
72+ resized_img = distorted_img .resize ((new_width , size - 10 ), Image .ANTIALIAS )
73+ background_width = width if width > 0 else new_width + 10
74+ background_height = size
75+ # Vertical text
76+ elif orientation == 1 :
77+ new_height = int (float (distorted_img .size [1 ] + 10 ) * (float (size ) / float (distorted_img .size [0 ] + 10 )))
78+ resized_img = distorted_img .resize ((size - 10 , new_height ), Image .ANTIALIAS )
79+ background_width = size
80+ background_height = new_height + 10
81+ else :
82+ raise ValueError ("Invalid orientation" )
7483
7584 #############################
7685 # Generate background image #
7786 #############################
7887 if background_type == 0 :
79- background = BackgroundGenerator .gaussian_noise (height , background_width )
88+ background = BackgroundGenerator .gaussian_noise (background_height , background_width )
8089 elif background_type == 1 :
81- background = BackgroundGenerator .plain_white (height , background_width )
90+ background = BackgroundGenerator .plain_white (background_height , background_width )
8291 elif background_type == 2 :
83- background = BackgroundGenerator .quasicrystal (height , background_width )
92+ background = BackgroundGenerator .quasicrystal (background_height , background_width )
8493 else :
85- background = BackgroundGenerator .picture (height , background_width )
94+ background = BackgroundGenerator .picture (background_height , background_width )
8695
8796 #############################
8897 # Place text with alignment #
0 commit comments