如何以编程方式批量添加图像条?

时间:2017-06-10 21:13:18

标签: python photoshop photos

我有成千上万的图像。我想批量编辑它们,在图片底部添加一个包含Instagram,Facebook和Twitter帐户用户名的条带。

示例图片位于:https://data.whicdn.com/images/254261469/large.jpg

可以使用Python以编程方式添加相同的条带。

1 个答案:

答案 0 :(得分:0)

给你一些开始的东西。下面的示例将使用Pillow / PIL库将图像粘贴到另一个图像中。它将徽标图像粘贴在原始图像左上角的(25,25)处并保存。

from PIL import Image

# Load the image you want to modify
image = Image.open('large.jpg')
print("Image size is ", image.size)

# Load the logo you want to paste in
logo = Image.open('logo.png')
# Decide what size you need possibly based on the first image?
# Here we are just reducing the size so it has a higher chance to fit
logo = logo.resize((logo.size[0] // 4, logo.size[1] // 4))

# Paste the logo into the image
image.paste(logo, (25, 25))

# Save the new image
image.save("test.jpg", format='jpeg')

您需要了解的其他事项:

  • 粘贴的图像必须与原始图像中显示的尺寸完全相同。这就是我添加调整大小代码的原因。
  • 如果您正在使用不同尺寸的图像,您可能需要找到有关如何放置新徽标的工作公式。希望它们能够一致地添加到所有图像中。
  • 请务必阅读枕头文档(下面的链接)
  • 使用jpg图像时,最终可能会降低图像质量。请参阅save方法的文档。

http://pillow.readthedocs.io/en/latest/reference/Image.html