0%

python基于PIL的图片编辑

示例

1
2
3
4
5
6
7
8
9
10
11
12
from PIL import Image, ImageDraw, ImageFont

bk_img = Image.open(os.path.join(path_image, '{}.jpg'.format(path_u[i]))) # open an image
draw = ImageDraw.Draw(bk_img) # prepare to draw on it
draw.text((10, 30), "epoch:{}".format(self.epoch), fill=(255, 255, 255)) # 1030行,内容,fill=字体颜色
draw.text((10, 60), "predict:{}".format(w_list), fill=(255, 0, 0))
draw.text((10, 110), "gt:{}".format(gt_list), fill=(0, 255, 0))

now_out_path = os.path.join(self.args.save_dir, 'wrong_prediction_best', '{}jpg'.format(path_u[i])) # 输出路径
bk_img.save(now_out_path) # 保存


-------------这么快就看完啦^ω^谢谢阅读哟-------------