In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to make Spring Festival couplets with Python". The editor shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "how to use Python to make Spring Festival couplets" can help you solve the problem.
1. Preface
Spring Festival couplets are one of the most connotative elements in Chinese traditional culture. They depict beautiful images and express good wishes in neat, concise and exquisite characters. It is a unique literary form in China and an important custom for Chinese people to celebrate the Chinese New year. During the Spring Festival, every household, whether in urban or rural areas, should select a pair of red Spring Festival couplets posted on the door to bid farewell to the New year and welcome the New year, so as to increase the festive atmosphere of the festival. According to textual research, this custom originated in the Song Dynasty and flourished in the Ming Dynasty. The earliest documented Spring Festival couplet is "Sanyang Shibu, the beginning of the fourth preface", which can be found in the cultural relics unearthed in the scriptures of the Mogao Grottoes. The author is Liu Qiuzi of the Tang Dynasty, which was written in 11 years of the Kaiyuan Dynasty (723 AD).
Most of the programmers of our time are only fluent in writing and writing, and they are basically not good at writing. However, the yearning for a better life is no less than the literati. With the help of the code, we can also write beautiful Spring Festival couplets and send our sincerest wishes and best wishes to our family, neighbors, friends and colleagues.
two。 The code needs to import the module import iofrom PIL import Imageimport numpy as npimport requests3. Download font def get_word (ch, quality): "" get a picture of a single Chinese character (character) ch-single Chinese character or English alphabet (uppercase only) quality-single character resolution, HMel 640 pixels, MMel 480 pixels LMQ 320 pixel "" fp = io.BytesIO (requests.post (url=' http://xufive.sdysit.com/tk', data= {'ch':ch}) .content) im = Image.open (fp) w, h = im.size if quality = =' fp: W, h = int (w = 0.75), int (0.75 h) elif quality = ='L é n: W, h = int (w) Int (0.5 minutes h) return im.resize ((wrecom h)) 4. Download the background picture of Dragon and Phoenix Chengxiang def get_bg (quality): "" get the picture of Spring Festival couplet background "" return get_word ('bg', quality) 5. " Generate Spring Festival couplets def write_couplets (text, HorV='V', quality='L', out_file=None): "" generate Spring Festival couplets text-Spring Festival couplets content, HorV-H-horizontal row with blanks, V-vertical quality-word resolution, Hmur640 pixels, Mmur480 pixels LMQ 320 pixel out_file-output file name "" usize = {'Houses: (640, 323),' mom: (480, 18) Bg_im = get_bg (quality) text_list = [list (item) for item in text.split ()] rows = len (text_list) cols = max ([len (item) for item in text_list]) if HorV = = 'quality: ow, oh = 40+rows*usize [quality] [0] + (rows-1) * 10, 40+cols*usize [quality] [0] else: ow Oh = 40+cols*usize [quality] [0], 40+rows*usize [quality] [0] + (rows-1) * 10 out_im = Image.new ('RGBA', (ow, oh),' # f0f0f0f0') for row in range (rows): if HorV = 'video: row_im = Image.new (' RGBA', (usize [quality] [0], cols*usize [quality] [0])) 'white') offset = (ow- (usize [quality] [0] + 10) * (row+1)-10,20) else: row_im = Image.new (' RGBA', (cols*usize [quality] [0], usize [quality] [0]), 'white') offset = (20,20 + (usizequality [0] + 10) * row) for col Ch in enumerate (text_ list [row]): if HorV = = 'col*usize: pos = (0, col*usize [quality] [0]) else: pos = (col*usize [quality] [0], 0) ch_im = get_word (ch, quality) row_im.paste (bg_im) Pos) row_im.paste (ch_im, (pos [0] + usize [quality] [1], pos [1] + usize [quality] [1]), mask=ch_im) out_im.paste (row_im, offset) if out_file: out_im.convert ('RGB') .save (out_file) out_im.show () 6. Test sample 6.1 celebrate the Spring Festival text = 'celebrate the Spring Festival' write_couplets (text, HorV='V', quality='M', out_file=' celebrate the Spring Festival. JPG')
Write_couplets (text, HorV='H', quality='M', out_file=' years like song. JPG')
6.3. although there is a hundred beauties in the world, you are the only one in my love text = 'you are the only one in the world' write_couplets (text, HorV='H', quality='M', out_file='. JPG')
This is the end of the content about "how to make Spring Festival couplets with Python". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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: 0
*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.