In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I'm going to talk to you about how to use Python to make a Wechat moments lucky draw. Many people may not know much about it. In order to make you understand better, the editor summarized the following contents for you. I hope you can get something from this article.
Recently I saw a funny lucky draw in moments:
Click on one at random:
Haha, laugh out the cry of a pig! This game makes use of the partial settings in the middle of the WeChat moments, which is funny but also contributes new ideas to the advertising and marketing of WeChat moments.
The process of making a map is not complicated, the corresponding part of the long map is well designed, and finally integrated together on the OK, it is a little troublesome to repeat the operation one by one. When I think of this, I can't help but tilt the corners of my mouth and smile, and use the PIL module of Python to generate a batch of pictures in Nine Palace, wouldn't it?
Design ideas
With reference to picture No. 1 seen in moments, we need to prepare a white background of 300 to 900, funny emoticons, slogans, an eye-catching number in the middle, and a mockery of "ha" below.
The idea of Python image processing is to find the corresponding location coordinates of the elements on the base map of the corresponding size, paste the prepared facial expressions through the PIL module, and add the corresponding advertising text to the pictures. I chose to add text to the number in the center of the picture. As for the bottom "ha", I made a direct map of a colorful "ha ha" picture.
Prepare the material
First of all, prepare 9 different emojis pictures online:
And colorful "ha ha" mocking pictures:
Nine different slogans refer to the pictures of moments at the beginning of the article. We correspond emoticons and slogans to different pictures of Nine Miyagi through Python Dictionary:
Content= {"back_img": "paper.jpg", "001": {"ad": 'boss, buy 10 boxes of mooncakes', "head": '001.jpg'}, "002": {"ad":' boss, buy 20 boxes of mooncakes', "head": '002.jpg'}, "003": {"ad":' boss Life is not easy, buy 50 boxes of mooncakes', "head": '003.jpg'}, "004": {"ad":' boss, buy 80 boxes of mooncakes, not many', "head": '004.jpg'}, "005": {"ad":' boss, look at the face You should buy 100 boxes of mooncakes', "head": '005.jpg'}, "006": {"ad":' boss, congratulations on winning the lottery, the prize is 150 boxes of mooncakes', "head": '006.jpg'}, "007": {"ad": boss, your staff asked me to tell you They want to eat mooncakes', "head": '007.jpg'}, "008": {"ad":' boss, I'll sell mooncakes and buy 200 boxes of mooncakes', "head": '008.jpg'}, "009": {"ad":' boss, donate 500 boxes of mooncakes', "head": '009.jpg'}
PIL image processing
PIL: Python Imaging Library is a powerful Python image processing library. Python 3 is installed through pip install Pillow, and the code file is imported through import PIL at the beginning. Here we will use mapping in PIL and writing text to the picture.
The mapping is realized through the Image module, and the picture is opened by Image.open (). If necessary, it can be scaled by resize (), and finally mapped at the given coordinates through paste ().
From PIL import Image# im is the background map im = Image.open (background) # head_img is the emoji to be posted. First zoom the uniform size head_img = Image.open (f "head/ {head}"). Resize ((150150), Image.ANTIALIAS) # paste the emoji im.paste (head_img, (75L20) on the 75200 coordinates of the background map)
Write text to the picture through the ImageDraw module, if you want to adjust the text size and font, you need to import ttf font file, it is important to note that some fonts do not support Chinese. Finally, the text is written to the specified location in the figure through PIL.ImageDraw.ImageDraw.text ().
From PIL import Image, ImageFont, ImageDrawim = Image.open (background)
Draw = ImageDraw.Draw (im) mark_font = ImageFont.truetype ("pre/arial.ttf", 100) draw.text ((125400), mark,font=mark_font,fill=
Detail processing
In the process of making the picture of the ninth palace grid, because the content is simple, it is good to directly manipulate the position of the elements. The only thing that can not be controlled is the length and content of the advertisement. Here we can simply identify the Chinese "," in the advertisement to break the sentence. Each broken short sentence is displayed in the picture in the middle of one line.
Since we are going to use the code to mass produce pictures, and what each picture currently changes are emoticons and slogans, in the code we encapsulate the process of generating a complete picture into a function, so that each time the function is called with the corresponding parameters, we can batch generate the nine-grid lucky draw we need.
# define the function get_pic (background,head,adcontent,mark,pic_name) for i in range (1p10) of Haosheng growth graph in advance: background = "pre/paper.jpg" head = content [fim00 {I}'] ['head'] adcontent = content [fim00 {I}'] ['ad'] get_pic (background,head,adcontent,f "{I}") F "{I} .jpg") print ("Nine Miyagi grid picture generation is complete!")
Code download
Download link for GitHub code and materials: https://github.com/pengfexue2/friends_ad.git
Baidu network disk code and material download: https://pan.baidu.com/s/10qqahokqPoc1KFJ7PyARxg password: H202
Final effect
After clicking, the long picture is as follows:
After reading the above, do you have any further understanding of how to use Python to make a Wechat moments lucky draw? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 278
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.