@@ -21,16 +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 ):
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 :
31+ if orientation == 1 :
32+ raise ValueError ("Vertical handwritten text is unavailable" )
3133 image = HandwrittenTextGenerator .generate (text )
3234 else :
33- image = ComputerTextGenerator .generate (text , font , text_color , height )
35+ image = ComputerTextGenerator .generate (text , font , text_color , size , orientation , space_width )
3436
3537 random_angle = random .randint (0 - skewing_angle , skewing_angle )
3638
@@ -64,23 +66,32 @@ def generate(cls, index, text, font, out_dir, height, extension, skewing_angle,
6466 # Resize image to desired format #
6567 ##################################
6668
67- new_width = int (float (distorted_img .size [0 ] + 10 ) * (float (height ) / float (distorted_img .size [1 ] + 10 )))
68-
69- resized_img = distorted_img .resize ((new_width , height - 10 ), Image .ANTIALIAS )
70-
71- 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" )
7283
7384 #############################
7485 # Generate background image #
7586 #############################
7687 if background_type == 0 :
77- background = BackgroundGenerator .gaussian_noise (height , background_width )
88+ background = BackgroundGenerator .gaussian_noise (background_height , background_width )
7889 elif background_type == 1 :
79- background = BackgroundGenerator .plain_white (height , background_width )
90+ background = BackgroundGenerator .plain_white (background_height , background_width )
8091 elif background_type == 2 :
81- background = BackgroundGenerator .quasicrystal (height , background_width )
92+ background = BackgroundGenerator .quasicrystal (background_height , background_width )
8293 else :
83- background = BackgroundGenerator .picture (height , background_width )
94+ background = BackgroundGenerator .picture (background_height , background_width )
8495
8596 #############################
8697 # Place text with alignment #
0 commit comments