Py学习  »  Python

如何用Python代码发一个炫酷的朋友圈

马哥Linux运维 • 3 年前 • 450 次点击  



50 PIL(Python Image Library)


9




9


Python











# -*- coding: utf-8 -*-'''9'''from PIL impo


    
rt Imageimport sys#def fill_image(image):    width, height = image.


    
size        #    new_image_length = width if width > height else h


    
eight        #[]    new_image = Image.new(image.mode, (new_image_length, new_


    
image_length), color='white')        # if width > height:#


    
 #(x,y)        new_image.paste(image, (0, int((new_image_leng


    
th - height) / 2)))    else:        new_image.paste(image, (int((new_image_length - 


    
width) / 2),0))        return new_image#def cut_image(image):    width, he


    
ight = image.size    item_width = int(width / 3)    box_list = []        # (left,


    
 upper, right, lower) for i in range(0,3):#9 for j in range(0,3):   


    
         #print((i*item_width,j*item_width,(i+1)*item_width,(j+1)*item_width))       


    
     box = (j*item_width,i*item_width,(j+1)*item_width,(i+1)*item_width)            bo


    
x_list.append(box)
image_list = [image.crop(box) for box in box_list] return image_list#def save_images(image_list): index = 1 for image in image_list: image.save('./result/python'+str(index) + '.png', 'PNG') index += 1
if __name__ == '__main__': file_path = "python.jpeg" i mage = Image.open(file_path) #image.show() image = fill_image(image) image_list = cut_image(image) save_images(image_list)

文章转载:Python编程学习圈
(版权归原作者所有,侵删)

点击下方“阅读原文”查看更多

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/122106