55from PIL import Image , ImageDraw , ImageFont
66
77
8- def create_image (text , font , index = 0 , image_size = (1920 , 1080 ),
9- bg_color = (255 , 255 , 255 ), font_color = (0 , 0 , 0 ),
10- save_location = "./resource/tmp" ):
8+ def create_image (text , font , index = 0 , image_size = (1920 , 1080 ),
9+ bg_color = (255 , 255 , 255 ), font_color = (0 , 0 , 0 ),
10+ save_location = "./resource/tmp" ):
1111 font_size = font .size
1212 # text treatment
1313 text = textwrap .wrap (text , width = font_size )
@@ -16,7 +16,7 @@ def create_image(text, font, index=0, image_size=(1920, 1080),
1616 img = Image .new ('RGB' , image_size , bg_color )
1717 draw = ImageDraw .Draw (img )
1818 # drawing lines in text with padding
19- current_h , pad = MAX_H / 2 - ((len (text )* font_size / 2 )), 10
19+ current_h , pad = MAX_H / 2 - ((len (text ) * font_size / 2 )), 10
2020 for line in text :
2121 w , h = draw .textsize (line , font = font )
2222 draw .text (((MAX_W - w ) / 2 , current_h ),
@@ -41,7 +41,7 @@ def create_frames(images, fps=10, duration_per_frame=3):
4141 img_array = []
4242 for filename in images :
4343 img = cv2 .imread (filename )
44- for i in range (fps * duration_per_frame ):
44+ for i in range (fps * duration_per_frame ):
4545 img_array .append (img )
4646 return img_array
4747
@@ -73,7 +73,7 @@ def remove_temp_files(files):
7373 images = []
7474 for idx , sentence in enumerate (sentences ):
7575 imagePath = create_image (
76- sentence , font , idx + 1 , image_size = dimensions )
76+ sentence , font , idx + 1 , image_size = dimensions )
7777 images .append (imagePath )
7878 # read all images
7979 frames = create_frames (images , fps = fps , duration_per_frame = 1 )
0 commit comments