利用Python给图片加文字

导入所需要的库

from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw

添加字体(需要设置,可以不设置),加文字, 代码参考如下

from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw

#打开底版图片
imageFile = "test.jpg"
tp=Image.open(imageFile)

# 在图片上添加文字
draw = ImageDraw.Draw(tp)
draw.text((100, 100),"测试文字",(255,255,0))

# 保存
tp.save("testOutput.png")

参考

[1] Python在图片上添加文字

CMake CMakeLists Conan Eigen FCPX Forge GNU Gazebo Git IBus Interest IsaacLab KDL Life Linux Matrix ODE PPO QoS ROS ROS2 Ros UML Ubuntu VcXsrv algorithm algorithms axis-angle bode c++ calibration chrome colcon control cpp dB data_struct dots figure gdb git latex launch life linux mac math matlab memory mlp motor moveit operator optimal algorithm python robot robotics ros ros2 rtb shell simulation stl thread tools twist unitree urdf valgrind velocity vim web work wsl 中文输入 交叉编译 依赖管理 分支管理 强化学习 构建系统 版本控制 输入法 配置类
知识共享许可协议