如何在python中调整框内的粘贴图像?

时间:2017-06-29 06:23:01

标签: python bots pillow

所以我一直在尝试使用PILLOW(一个PIL fork)在python中创建一个meme bot,基本上它需要一个随机模板和一个随机源图像并将它们组合在一起。

到目前为止,我设法创建了一个将源图像充分放入模板中的版本,但无法调整大小。这是我的代码:

P上。 S.我主要使用C编写代码,所以我的python ain非常棒

from PIL import Image, ImageOps
import os, random
import re
import linecache
import string

temp_dir = "temp dir"
source_dir = "source dir"
memes_dir = "memes dir"

#Random template & source image
rand_temp = random.choice(os.listdir(temp_dir))
rand_source = random.choice(os.listdir(source_dir))

#template
bot = Image.open(temp_dir + rand_temp)

#source image
top = Image.open(source_dir + rand_source) 

width, height = bot.size
size = (width, height)

#Puts Source image in template
meme = ImageOps.fit(top, size, Image.ANTIALIAS)
meme.paste(bot, (0,0), bot)
meme.show()

有没有办法实现我想要的?或者我应该转向另一种语言?谢谢!

0 个答案:

没有答案