In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points about how to use Python to send holiday wishes to teachers. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Sunflower
Sunflower language includes: faith, brilliance, loyalty, etc., very suitable for teachers, let's first draw a simple sunflower.
The implementation code is as follows:
Turtle.setup (600,600,80 80) turtle.pencolor ("yellow") turtle.pensize (4) turtle.penup () turtle.fd (- 150) turtle.pendown () for i in range (18): turtle.fd (300) turtle.left (100) turtle.fd (90) turtle.pensize (8) turtle.pencolor ("green") turtle.fd (400) turtle.penup (6) turtle.pendown () # draw leaves turtle.fd (- 250,250) turtle.seth (45) turtle.circle (- 130th) 60) turtle.seth turtle.circle (- 130,60) turtle.seth (135,135) turtle.circle (130,60) turtle.seth (- 45) turtle.circle (130,60) turtle.done () greeting card
We can also use Python to add some text to the photos to make greeting cards.
The main implementation code is:
Img = cv2.imread ('test.png') mask = np.zeros (img.shape [: 2], np.uint8) size = (1,65) bgd = np.zeros (size, np.float64) fgd = np.zeros (size, np.float64) rect = (1,1, img.shape [1], img.shape [0]) cv2.grabCut (img, mask, rect, bgd, fgd, 10, cv2.GC_INIT_WITH_RECT) mask2 = np.where (mask = 2) | (mask = 0), 1 Img = img.astype (np.int32) img * = mask2 [:,:, np.newaxis] IMG [IMG > 255] = 255img = img.astype (np.uint8) img = cv2.cvtColor (img, cv2.COLOR_BGR2RGB) img = Image.fromarray (img, 'RGB') img.save (' test1.jpg') fp = open (r "word.txt", "r" Encoding= "utf-8") text = fp.read () mask_pic=np.array (Image.open (r "test1.jpg")) wordcloud = WordCloud (font_path='hyr3gjm.ttf',mask=mask_pic,max_words=200). Generate (text) image=wordcloud.to_image () image.save ("wordcloud2.png") cloud_data = np.array (image) alpha = np.copy (cloud_data [:,:, 0]) alpha [alpha > 0] = 255new_image = Image.fromarray (np.dstack ((cloud_data) Alpha)) card = Image.open ("test.png") card = card.convert ("RGBA") card.paste (new_image, (0Power0), mask=new_image) card.save ("card.png") Photo Wall
We can also use Python to make some photos into text-effect photo walls.
The main implementation code is:
# def char2bit (textStr): KEYS = [0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02] for converting characters into Chinese character libraries 0x01] target = [] global count count = 0 for x in range (len (textStr)): text = textStr [x] rect_list = [] * 16 for i in range (16): rect_list.append ([] * 16) gb2312 = text.encode ('gb2312') hex_str = binascii.b2a_hex (gb2312) result = str (hex_str) Encoding='utf-8') area = eval ('0x' + result [: 2])-0xA0 index = eval (' 0x' + result [2:])-0xA0 offset = (94 * (area-1) + (index-1)) * 32 font_rect = None with open ("HZK16") "rb") as f: f.seek (offset) font_rect = f.read (32) for k in range (len (font_rect) / / 2): row_list = rect_ list [k] for j in range (2): for i in range (8): asc = font_ * 2 + j] flag = asc & KEYS [I] row_list.append (flag) output = [] for row in rect_list: for i in row: if I: output.append ('1') count+=1 else: Output.append ('0') target.append ('. Join (output)) return target# generates picture text def head2char (workspace) Folder,self Outlist): # transfer the work path to the avatar folder os.chdir (folder) # get the list of avatars in the folder imgList = os.listdir (folder) # get the number of avatars numImages = len (imgList) # set the size of the avatar after cropping eachSize = 100 # variable n is used to cycle through the avatar image nportrait 0 # variable count is used for The resulting word picture number count = 0 # initializes the color list For background shading colorlist = ['# FFFACD','#F0FFFF','#BFEFFF','#b7facd','#ffe7cc','#fbccff','#d1ffb8','#febec0' '# E0EEE0'] # index is used to change the background color of different words index = 0 # the lattice information of each item corresponds to different words for item in outlist: # change the work path to the folder where the avatar is located os.chdir (folder) # create a new canvas with background color 16 * 16 lattice, each point is filled with 2 * 2 avatars, so the length is 16 * 2 * 100 canvas = Image.new ('RGB', (3200, 3200), colorlist [index]) # create a new canvas # index transform, which is used to transform the background color index = (index+1)% 9 count + = 1 # each 16 * 16 dot matrix Fill for i in range (16x16) with four 100x100 avatars: # Lattice information is 1 That is to say, the word if item [I] = = "1": # read four consecutive avatars x1 = n% len (imgList) x2 = (nasty 1)% len (imgList) x3 = (nasty 2)% len (imgList) x4 = (nasty 3) % len (imgList) # the following four groups of try Fill the four avatars you read into a corresponding point on the drawing board # the picture in the upper left corner at the dot matrix 1 try 4: # Open the picture img = Image.open (imgList [x1]) except IOError: print ("one picture failed to read Replaced ") img = Image.open (self) finally: # reduced image img = img.resize ((eachSize, eachSize), Image.ANTIALIAS) # mosaic image canvas.paste (img, (I% 16) * 2 * eachSize (I / / 16) * 2 * eachSize) # the image in the upper right corner of the dot matrix 2 try 4 try: img = Image.open (imgList [x2]) except IOError: print ("1 image failed to read Replaced with alternate image ") img = Image.open (self) finally: img = img.resize ((eachSize, eachSize), Image.ANTIALIAS) canvas.paste (img, ((I% 16) * 2 + 1) * eachSize (I / / 16) * 2 * eachSize) # the image in the lower left corner of the dot matrix 3 try 4 try: img = Image.open (imgList [x3]) except IOError: print ("1 image failed to read Replaced with alternate image ") img = Image.open (self) finally: img = img.resize ((eachSize, eachSize), Image.ANTIALIAS) canvas.paste (img, (I% 16) * 2 * eachSize ((I / / 16) * 2 + 1) * eachSize) # the image in the lower right corner at the lattice 4 try: img = Image.open (imgList [x4]) except IOError: print ("one image failed to read Replaced with alternate image ") img = Image.open (self) finally: img = img.resize ((eachSize, eachSize), Image.ANTIALIAS) canvas.paste (img, ((I% 16) * 2 + 1) * eachSize ((I / / 16) * 2 + 1) * eachSize) # adjust n to read the subsequent picture n = (nim4)% len (imgList) os.chdir (workspace) # create a folder to store the output if not os.path.exists ('output'): os.mkdir (' output') Os.chdir ('output') # stores the stitched pictures Quality for picture quality, 1-100100 highest canvas.save ('result%d.jpg'% count, quality=100) above is "how to use Python to send holiday wishes to teachers" all the content of this article, thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.