Some time ago, I got a recommendation on Weibo. The content is like this
Out of curiosity, I clicked on it, zoomed in and zoomed in again, emmm, it’s kind of interesting...
Look at the case first
Original image
After generation (zoom in to see, hehehe)
This effect can be named "there are words in the painting". For those who want to confess and are shy, this trick is really a good way: it conveys what you want to say without being too obtrusive.
As a programmer, this can't help but arouse my geek heart! I immediately made the same tool by myself.
Today I will teach you this routine:
How to use Python to make this kind of romantic and geeky "connotation" map.
Of course, whether you can rely on it to get the favor of your favorite object depends on you (fate). (๑•́₃ •̀๑)
So what should we do?
Above code:
from PIL import Image, ImageDraw, ImageFont
font_size =7
text ="I like you!"
img_path ="yy.jpg"
img_raw = Image.open(img_path)
img_array = img_raw.load()
img_new = Image.new("RGB", img_raw.size,(0,0,0))
draw = ImageDraw.Draw(img_new)
font = ImageFont.truetype('C:/Windows/fonts/Dengl.ttf', font_size)
def character_generator(text):while True:for i inrange(len(text)):yield text[i]
ch_gen =character_generator(text)for y inrange(0, img_raw.size[1], font_size):for x inrange(0, img_raw.size[0], font_size):
draw.text((x, y),next(ch_gen), font=font, fill=img_array[x, y], direction=None)
img_new.convert('RGB').save("save_yy.jpeg")