1

So I've been trying to make a meme bot, in python using PILLOW (a PIL fork) basically it takes a random template and a random source image and puts them together.

So far I managed to make a version which puts the source image adequately in the template, but fails to resize it. Here's my code:

P. S. I mainly code in C, so my python ain't that great

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()

Is there any way to achieve what I want? Or should I maybe move to another language? Thanks!

  • Have you tried using PIL's resize or thumbnail functions? Note that fit does not maintain aspect ratio. https://stackoverflow.com/questions/273946/how-do-i-resize-an-image-using-pil-and-maintain-its-aspect-ratio – BoboDarph Jun 29 '17 at 08:21

0 Answers0