In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to write a blessing word in python". In daily operation, I believe many people have doubts about how to write a blessing word in python. The editor consulted all kinds of materials and sorted out simple and easy operation methods. I hope to help you answer the doubts about "how to write a blessing word in python"! Next, please follow the small series to learn together!
Foreword:
Alipay 2022 set of five blessings officially opened
Data show that over the past six years, more than 700 million people have participated in Alipay's collection of five blessings, and one out of every two Chinese people has swept blessings, collected blessings and sent blessings.
One, sweep five blessing activity is so popular, why not use their own programming to generate blessing word!
First of all, the works are presented:
1, import python library
import iofrom PIL import Imageimport requests
②, using reptiles to obtain single Chinese characters
def get_word(ch, quality): 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 == 'M': w, h = int(w*0.75), int(0.75*h) elif quality == 'L': w, h = int(w*0.5), int(0.5*h) return im.resize((w,h))
def get_word is used to crawl the Chinese character model we need.
As shown in the figure:
③ Climb the background map
def get_bg(quality): return get_word('bg', quality)
④, picture format size, configuration function
def write_couplets(text, HorV='V', quality='L', out_file=None): usize = {'H':(640,23), 'M':(480,18), 'L':(320,12)} 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 == 'V': 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), '#f0f0f0') for row in range(rows): if HorV == 'V': 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+(usize[quality][0]+10)*row) for col, ch in enumerate(text_list[row]): if HorV == 'V': 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()
5, finished product display
Two, complete code.
Complete code is provided, you need to install the required python library first.
import iofrom PIL import Imageimport requestsdef get_word(ch, quality): 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 == 'M': w, h = int(w*0.75), int(0.75*h) elif quality == 'L': w, h = int(w*0.5), int(0.5*h) return im.resize((w,h))def get_bg(quality): return get_word('bg', quality)def write_couplets(text, HorV='V', quality='L', out_file=None): usize = {'H':(640,23), 'M':(480,18), 'L':(320,12)} 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 == 'V': 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), '#f0f0f0') for row in range(rows): if HorV == 'V': 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+(usize[quality][0]+10)*row) for col, ch in enumerate(text_list[row]): if HorV == 'V': 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()text = 'fu'write_couples (text, HorV='V', quality=' M', out_file='fu.jpg') At this point, the study of "how to write a fu word in python" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
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.