嗯,很可爱的狗狗,本想找个美女,但怕惹麻烦,就找了个狗狗。文章源自陈学虎-https://chenxuehu.com/article/2020/07/7618.html
然后我们来跑下这个脚本文章源自陈学虎-https://chenxuehu.com/article/2020/07/7618.html
from PIL import Image, ImageDraw, ImageFont import cv2 def draw(pic, draw_text): img = cv2.imread(pic) blank = Image.new("RGB", [img.shape[1], img.shape[0]], "white") drawObj = ImageDraw.Draw(blank) n = 10 m = 9 font = ImageFont.truetype("simkai.ttf", size=12) for i in range(0, img.shape[0], n): for j in range(0, img.shape[1], n): drawObj.text( [j, i], draw_text[int(j / n) % len(draw_text)], fill=(img[i][j][2], img[i][j][1], img[i][j][0]), font=font ) blank.save('img_1.jpg') draw('C://Users/Kevin/Desktop/dog.jpg', "我爱你")
文章源自陈学虎-https://chenxuehu.com/article/2020/07/7618.html
效果是:文章源自陈学虎-https://chenxuehu.com/article/2020/07/7618.html
文章源自陈学虎-https://chenxuehu.com/article/2020/07/7618.html
文章源自陈学虎-https://chenxuehu.com/article/2020/07/7618.html
因为图片比较小,因此你看到的字就比较明显了,应该适当的调节下大写,为了演示,就不做太多的效果了,文章源自陈学虎-https://chenxuehu.com/article/2020/07/7618.html
应用场景,如果想让你女朋友高兴一下,是不是可以把你们的合照全部写上“我爱你”的字呢,那会是什么效果呢?文章源自陈学虎-https://chenxuehu.com/article/2020/07/7618.html 文章源自陈学虎-https://chenxuehu.com/article/2020/07/7618.html
评论