glt3953 commited on
Commit
98b5d53
·
1 Parent(s): 5683f50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -7,7 +7,7 @@ from tqdm import tqdm
7
  import datetime
8
  import os
9
  import gradio as gr
10
- from PIL import Image
11
  from translate import Translator
12
  from gradio_client import Client
13
  import json
@@ -97,6 +97,23 @@ def inference(original_prompt: str, image: Image) -> Image:
97
  res_img = Image.open(result_path)
98
  print('作品:' + result_path)
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  return res_img
101
 
102
 
 
7
  import datetime
8
  import os
9
  import gradio as gr
10
+ from PIL import Image, ImageDraw, ImageFont
11
  from translate import Translator
12
  from gradio_client import Client
13
  import json
 
97
  res_img = Image.open(result_path)
98
  print('作品:' + result_path)
99
 
100
+ # 加载字体,设置字体大小
101
+ font_path = 'ttf/WawaSC-Regular.otf'
102
+ font_size = 50
103
+ font = ImageFont.truetype(font_path, font_size)
104
+ text = 'by 宁侠'
105
+
106
+ x0, y0, x1, y1 = font.getbbox(text)
107
+ text_width = x1 - x0
108
+ text_height = (y1 - y0)*2
109
+
110
+ watermark = Image.new('RGBA', (text_width, text_height))
111
+ draw = ImageDraw.Draw(watermark)
112
+ draw.text((0,0), text, font=font, fill=(255,255,255)) #阿根廷蓝:112,171,221
113
+
114
+ w, h = res_img.size
115
+ res_img.paste(watermark, (w - text_width - 10, h - text_height), watermark)
116
+
117
  return res_img
118
 
119