( First love face King Bingbing breaks the circle , You think CCTV doesn't understand young people ? )
last year 11 month , CCTV cameraman wangbingbing is a reporter because “ First love face ” popular , Many people have changed their traditional impression of CCTV's prudence
view . Wangbingbing has also become the favorite of many netizens “ The goddess ”, So how do programmers express their feelings like girls in their hearts ?
I want to use my recent knowledge of image processing , Add hidden words to the picture !
( The normal browsing of the mobile phone is a photo , Zoom in to see the text inside )
People with objects and without objects can use this code to express their favorite people ~
One 、 Effect display
The image of Bingbing must be the original image with larger pixels :
design sketch :( You can't see the text clearly in the mobile preview )
You can only see clearly after zooming in :( Words can be used whatever they like )
Be careful : The resulting image may be distorted when enlarged , Text blur . I found a website on the Internet , Can be enlarged without damage
slice . To upload pictures , Select the magnification , Select the highest noise reduction , You can generate... In about two minutes .
Finally, share this website with you :https://bigjpg.com/
Two 、 The source code to achieve
from PIL import Image, ImageDraw, ImageFont
font_size = 7
text = " I like you !"
img_path = "04.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('Calibri.ttf', font_size)
def character_generator(text):
while True:
for i in range(len(text)):
yield text[i]
ch_gen = character_generator(text)
for y in range(0, img_raw.size[1], font_size):
for x in range(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_04.jpeg")
If I think my sharing is good , Welcome to join us for the third time ~
Whole material, etc : Didi I I acridine ! Or take it for free at the end of the article ~
Summary : Python Collection of articles | ( Introduction to actual combat 、 game 、Turtle、 Case etc. )
( There are more cases waiting for you to learn ~ You can find me for free !)