diff --git a/BaiHu/Test/WriteWenZi.py b/BaiHu/Test/WriteWenZi.py new file mode 100644 index 00000000..49e097e4 --- /dev/null +++ b/BaiHu/Test/WriteWenZi.py @@ -0,0 +1,27 @@ +from PIL import Image, ImageDraw, ImageFont + + +def WriteWenZi(image_path): + # 打开图片 + image = Image.open(image_path) + + # 创建字体对象 + font = ImageFont.truetype('arial.ttf', size=24) + + # 创建绘图对象 + draw = ImageDraw.Draw(image) + + # 设置文本内容和坐标 + text = 'Created by AI' + x = image.width - 200 + y = image.height - 50 + + # 绘制文本 + draw.text((x, y), text, font=font, fill='white') + + # 保存修改后的图片 + image.save(image_path) + image.close() + + +WriteWenZi("d:\\9.png") diff --git a/BaiHu/doTask.py b/BaiHu/doTask.py index 14613777..95f4999f 100644 --- a/BaiHu/doTask.py +++ b/BaiHu/doTask.py @@ -8,10 +8,34 @@ from Util.SDUtil import * from Util.CommonUtil import * from Util.OssUtil import uploadOss from Util.PngUtil import * +from PIL import Image, ImageDraw, ImageFont +def WriteWenZi(image_path): + # 打开图片 + image = Image.open(image_path) + + # 创建字体对象 + font = ImageFont.truetype('arial.ttf', size=24) + + # 创建绘图对象 + draw = ImageDraw.Draw(image) + + # 设置文本内容和坐标 + text = 'Created by AI' + x = image.width - 200 + y = image.height - 50 + + # 绘制文本 + draw.text((x, y), text, font=font, fill='white') + + # 保存修改后的图片 + image.save(image_path) + image.close() def upload_img_file(file_path, model_id): png_file = os.path.basename(file_path) + # 添加水印信息 + WriteWenZi(file_path) # 清除Exif信息 clearExif(file_path, file_path) # 清除Exif信息 # 上传到OSS