import string
import random
# path to the image
path = u"https://yourimage.jpg"
# get the size of the image
print(imageSize("https://yourimage.jpg"))
# w, h = imageSize(path) s = letter size
w = 400
h = 400
s = 10
# Set the characters you need
chars = 'HOLAhola'
print (random.choice(chars))
# Get colors
pix_cols = {}
for x in range(0, w, s):
for y in range(0, h, s):
pix_cols[(x, y)] = imagePixelColor(path, (x, y))
# Variable font to use
"""
FontName
wdth {'name': 'Width', 'minValue': 100.0, 'maxValue': 800.0, 'defaultValue': 100.0}
wght {'name': 'Weight', 'minValue': 150.0, 'maxValue': 800.0, 'defaultValue': 150.0}
slnt {'name': 'Slant', 'minValue': 0.0, 'maxValue': 14.0, 'defaultValue': 0.0}
"""
min_val_wdth = listFontVariations('FontName')['wdth']['minValue']
max_val_wdth = listFontVariations('FontName')['wdth']['maxValue']
min_val_wght = listFontVariations('FontName')['wght']['minValue']
max_val_wght = listFontVariations('FontName')['wght']['maxValue']
min_val_slnt = listFontVariations('FontName')['slnt']['minValue']
max_val_slnt = listFontVariations('FontName')['slnt']['maxValue']
def ranLetters():
# loop over the width of the image
newPage(w, h)
fill(1)
rect(0, 0, w, h)
for x in range(0, w, s):
# loop of the height of the image
for y in range(0, h, s):
color = pix_cols[(x, y)]
if color:
txt = random.choice(chars)
font("FontName")
fontSize(s)
fontVariations(wdth = randint(min_val_wdth, max_val_wdth), wght = randint(min_val_wght, max_val_wght))
r, g, b, a = color
# set the color
fill(r, g, b, a)
# draw some text
text(txt, (x, y), align='center')
for i in range(5):
ranLetters()
saveImage("~/Desktop/name.gif", imageResolution=144)