samedi 25 septembre 2021

How do I pull a randomly chosen string from an array into PIL's text function and use in metadata

If I pull a random element of an array of strings, how do I need that specific element to be written with a certain font, color, placement, etc, and placed on top of a png file that I created?

   def create_new_image():
    new_image = {}
    new_image ["soft_skill"] = random.choices(soft_skill)[0]
    
    if new_image in all_images:
        return create_new_image()
    else:
        return new_image

for i in range(TOTAL_IMAGES):
    new_trait_image = create_new_image()
    all_images.append(new_trait_image)

im10 = ImageDraw.Draw(img)
im10.text((88,912),"PLACE_HERE", font=myFont, fill = (0,255,10))

In the "random.choices(soft_skill)", soft_skill is simply an array of about 100ish strings. One of them is picked randomly, and the result is then sent to a metadata file. I need to pick whatever string that was chosen in that line, and place it in the spot that says "PLACE_HERE" so that I can layer it on top of the png, while still keeping it in the metadata. This might be a simple question, but please help. Thank you.




Aucun commentaire:

Enregistrer un commentaire