import os,random
import string
from PIL import Image,ImageDraw, ImageFont
def random_string_generator(str_size, allowed_chars):
return ''.join(random.choice(allowed_chars) for x in range(str_size))
def view_img(str):
print(str)
for i in range(1, 10):
folder1=r"E:/baibhav/MPEG7dataset/Distinct_images"
a=random.choice(os.listdir(folder1))
print(a)
file1 = folder1+'\\'+a
img1 = Image.open(file1).convert("RGBA")
#img1.show()
width, height = img1.size
center = (int(0.5 * width), int(0.5 * height))
#yellow = (100, 100, 0, 255)
colour_list = ((255,0,0,255),(0,255,0,255),(0,0,255,255),(210,105,30,255),(255, 255, 0, 255),(0,255,255,255),(128,128,128,255),(255,0,255,255),(100, 100, 0, 255),(100,0,255,255),(0,100,100,255))
#col = random.choice(colour_list)
ImageDraw.floodfill(img1, xy=center, value=random.choice(colour_list))
#img3.load()
#img2 = img1;
#img1.show()
chars = string.ascii_letters
size = 1
print(chars)
print('Random alphabet is', random_string_generator(size, chars))
# initialise the drawing context with
# the image object as background
draw = ImageDraw.Draw(img1)
font = ImageFont.truetype('Roboto-Bold.ttf', size=100)
(x, y) = (150, 150)
name = random_string_generator(size, chars)
color = 'rgb(255, 255, 255)' # white color
draw.text((x, y), name, fill=color, font=font)
# save the edited image
#img1.show()
img1.save("H:/superimpose/filename"+str(i)+".png", 'PNG')
0 Comments
Sign in to comment.