|
@@ -108,7 +108,7 @@ def make_dir(name_hash):
|
|
|
except FileExistsError:
|
|
|
print("~~~~~~Warning~~~~~~~~~Directory " , dir_subtitle+name_hash , " already exists")
|
|
|
|
|
|
-def file_prepare(name, name_hash,text_content,image_urls,lang):
|
|
|
+def file_prepare(name, name_hash,text_content,image_urls,lang='zh'):
|
|
|
make_dir(name_hash)
|
|
|
img_num = 1
|
|
|
for imgu in image_urls:
|
|
@@ -146,11 +146,15 @@ def file_prepare(name, name_hash,text_content,image_urls,lang):
|
|
|
txt_idx+=1
|
|
|
print("mp3 file made")
|
|
|
#make title as image
|
|
|
- txt2image_title(name, dir_title+name_hash+".png")
|
|
|
+ txt2image_title(name, dir_title+name_hash+".png",lang)
|
|
|
|
|
|
-def txt2image(content, save_target):
|
|
|
+def txt2image(content, save_target,lang='zh'):
|
|
|
unicode_text = trim_punctuation(content)
|
|
|
- font = ImageFont.truetype(font="font/DFT_B7.ttc", size=38)
|
|
|
+ font = ''
|
|
|
+ if lang=='zh':
|
|
|
+ font = ImageFont.truetype(font="font/DFT_B7.ttc", size=38)
|
|
|
+ else :
|
|
|
+ font = ImageFont.load("arial.pil")
|
|
|
text_width, text_height = font.getsize(unicode_text)
|
|
|
canvas = Image.new('RGBA', (700, 500), (255, 0, 0, 0) )
|
|
|
draw = ImageDraw.Draw(canvas)
|
|
@@ -158,9 +162,13 @@ def txt2image(content, save_target):
|
|
|
draw.text((5,5), text, (255, 255, 0), font)
|
|
|
canvas.save(save_target, "PNG")
|
|
|
|
|
|
-def txt2image_title(content, save_target):
|
|
|
+def txt2image_title(content, save_target, lang='zh'):
|
|
|
unicode_text = trim_punctuation(content)
|
|
|
- font = ImageFont.truetype(font="font/DFT_B7.ttc", size=28)
|
|
|
+ font = ''
|
|
|
+ if lang=='zh':
|
|
|
+ font = ImageFont.truetype(font="font/DFT_B7.ttc", size=38)
|
|
|
+ else :
|
|
|
+ font = ImageFont.load("arial.pil")
|
|
|
text_width, text_height = font.getsize(unicode_text)
|
|
|
canvas = Image.new('RGBA', (510, 500), (255, 0, 0, 0) )
|
|
|
draw = ImageDraw.Draw(canvas)
|
|
@@ -240,7 +248,7 @@ def generate_subtitle_image_ENG(name_hash,text_content):
|
|
|
for idx in range(len(text_content)):
|
|
|
sv_path = dir_subtitle + name_hash +'/'+str(idx)+'.png'
|
|
|
sub = text_content[idx]
|
|
|
- txt2image(sub, sv_path)
|
|
|
+ txt2image(sub, sv_path,lang='eng')
|
|
|
img_list[idx] = sv_path
|
|
|
return img_list
|
|
|
|
|
@@ -389,7 +397,7 @@ def anchor_video_v2(name_hash,name,text_content, image_urls,avatar):
|
|
|
|
|
|
|
|
|
def anchor_video_eng(name_hash,name,text_content, image_urls,sub_titles,avatar):
|
|
|
- file_prepare(name, name_hash, text_content,image_urls,1)
|
|
|
+ file_prepare(name, name_hash, text_content,image_urls,'eng')
|
|
|
sub_list=generate_subtitle_image_ENG(name_hash,sub_titles)
|
|
|
|
|
|
for fname in range(len(text_content)):
|