The goal is to have a Python program that modifies a group of images by printing text on them from a user form. I've done it with a single image and works great! However I'm struggling with the usage of
for and creating filenames numbered as 1,2,3. as a suffix. Program should modify all files (images) in folder 1 and output the result in folder 2. What I have done thus far is below:
(Bear with me, I'm an experienced Dev learning Python while running a business - thank you)
What I have tried:
#Begin
#Written by Crediblock.com LLC
#Session Info
# Function to display hostname and
# IP address
# Driver code
#Function call
#Display IP
#Log IP to file
#Create session ID
# import required classes
from PIL import Image, ImageDraw, ImageFont
import glob
import os
path1 = "bm1"
path2 = "bm1-output"
# import form data
message1 = "Message"
# create Image object with the input image
# image = Image.open('background1.jpg')
image_list = []
for filename in glob.glob('bm1/*.jpg'):
im=Image.open(filename)
image_list.append(im)
# initialise the drawing context with
# the image object as background
draw = ImageDraw.Draw(image_list)
# create font object with the font file and specify
# desired size
font = ImageFont.truetype('Roboto-Bold.ttf', size=45)
# starting position of the message
(x, y) = (50, 50)
message = message1
color = 'rgb(0, 0, 0)' # black color
# draw the message on the background
draw.text((x, y), message, fill=color, font=font)
(x, y) = (150, 150)
name = 'THINK'
color = 'rgb(255, 255, 255)' # white color
draw.text((x, y), name, fill=color, font=font)
# save the edited image
for i in range(10):
image_list.save('filenames_%d\r\n"%(i+1).jpg')
# image_list.save('background_b2.jpg')
# optional optimization image.save('optimized.png', optimize=True, quality=20)