Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用 python 在背景图像中嵌入文本。背景图片为1.jpg,文字图片为2.jpg。背景图像包含我想在其上嵌入包含场景文本“Poppins”的文本区域 2.jpg 的墙壁。有人可以帮我写代码吗?
给出了样本输入
示例输出有点像这样:
虽然我用油漆做过!!最初的示例输出应如下所示,其中自然场景文本嵌入图像背景中
示例文本图像是:
哪个是提取的场景文本
如果要将一个图像粘贴到另一个图像之上,您的文本文件应该是一个 .png 文件(这样覆盖文件不包含背景数据),那么您可以使用以下代码,导入 PIL 库:
from PIL import Image image1 = Image.open('img1.jpg') image2 = Image.open('img2.png') image1.paste(image2, (0,0)) image1.show()
更改 (0,0) 值以在 x,y 坐标上移动 png 文本图像。