程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python applet] hidden confession diagram: you never know I like you (recommended to save)

編輯:Python

Preface

( 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 ~

Text

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")

summary

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 ~

There are more source code waiting for you to lead the area !

A summary 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 !)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved