So, I wrote this sript, which takes command line arguments and generates images based on them (there is only one argument now), it works prety good until it gets to the save function, I don't know why but it just takes the last image and saves it 10 times instead of saving every image
Here is the code;
import os, argparse
from PIL import Image as image
from PIL import ImageDraw as image_draw
from PIL import ImageFont as image_font
parser = argparse.ArgumentParser(description='Image generator')
#Argument definition
parser.add_argument('-num', action='store_true', required=False, help='Generates numbers')
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
args = parser.parse_args()
arg_num = args.num
def img_gen(n, lenght):
text = n
fnts = 20
fnt = image_font.truetype('Roboto.ttf', size=fnts, index=0, encoding='', layout_engine=None)
gen_i_width = (6 * fnts)
gen_i_height = (3 * fnts)
gen_img = image.new('RGBA', (gen_i_width, gen_i_height), color=(0, 0, 0, 255))
gen_text = image_draw.Draw(gen_img)
gen_text.text((0,0), text, font=fnt, fill=(255, 255, 255, 255))
text_size = gen_text.textsize(text, font=fnt, spacing=0, direction=None, features=None)
text_s_list = list(text_size)
text_width, text_height = text_s_list
img_c = gen_img.crop((0, 0, text_width, text_height))
for file_name in range(1, lenght + 1):
img_c.save(f"{file_name:04d}.png")
def main():
if arg_num == True:
lenght = len(numbers)
for n in numbers:
img_gen(n, lenght)
if __name__ == '__main__':
main()