I am trying to generate random images of text and store them as image files in my computer so that I can use them to train a model later. But I don't know how make sure all the characters falls within the image boundaries. When I plot them out in python they always show, but if I looked at the saved image, some times the strings are cut. Also, I want to automate the process instead of plotting each out to check.
Furthermore, setting bbox_inches='tight'
changes the image size, while I want to be able to specify the image size.
This is what I have tried so far
import matplotlib.pyplot as plt
import numpy as np
dpi = 100
h, w = 50, 100
plt.figure(figsize=(w / dpi, h / dpi), dpi=dpi)# so I will get w columns and h rows
text = str(np.random.uniform(100000, 1000000))# my string will always only be 6 characters
x = np.random.uniform(0, .3)# random positions
y = np.random.uniform(0, .5)
size = np.random.uniform(16, 23)# random text size
plt.text(x, y, text, fontdict={'size': size})
plt.axis('off')
plt.savefig(text + '.jpg'))