python - 如何使用python将文本放在多个图像上?
问题描述
from PIL import Image, ImageDraw, ImageFont
import glob
import os
images = glob.glob("directory_path/*.jpg")
for img in images:
images = Image.open(img)
draw = ImageDraw.Draw(images)
font = ImageFont.load_default() #Downloaded Font from Google font
text = "Text on all images from directory"
draw.text((0,150),text,(250,250,250),font=font)
images.save(img)
我必须在所有图像上添加文字,我已经尝试了上面的代码,但它不起作用
解决方案
Here is the solution
from PIL import Image,ImageDraw,ImageFont
import glob
import os
images=glob.glob("path/*.jpg")
for img in images:
images=Image.open(img)
draw=ImageDraw.Draw(images)
font=ImageFont.load_default()
text="Whatever text"
draw.text((0,240),text,(250,250,250),font=font)
images.save(img)
推荐阅读
- powershell - 使用 Get-ADUser 过滤掉包含单词或字符的用户
- oracle - 如何在多列上的 oracle 行之间查找重复项?
- java - 无法通过 Java 检索存储过程返回值
- spring-boot - spring-boot-starter-freemarker 动态循环示例
- javascript - 在后台打开新标签,将注意力集中在当前标签上 - Chrome
- neo4j - 由于 PicklingError,Pyspark 操作未执行
- javascript - 根据我输入的 id 显示自动完成选择
- node.js - sinon mocking GET, POST, PUT and DELETE methods assertions fail everytime. no idea why
- javascript - 设置 laravel 护照的到期时间
- apache - 大规模 301 重定向 - 这是最好的方法?htaccess 或 httpd.conf