调用系统的语言功能及图片的处理
from PIL import Image img = Image.open('11.jpg') img_mode = img.mode print(img_mode) dr = img.size print(dr) xs = img.getpixel((0,0)) print(xs) ''' RGB (500, 500) (122, 114, 93) ''' new = Image.new('L',img.size,255) width,height = img.size img = img.convert('L') pen_size = 3 Color_Diff = 6 for i in range(pen_size+1,width-pen_size -1): for j in range(pen_size+1,height-pen_size-1): originalcolor = 255 lcolor = sum([img.getpixel((i-r,j))for r in range(pen_size)])//pen_size rcolor = sum([img.getpixel((i+r,j))for r in range(pen_size)])//pen_size if abs(lcolor-rcolor)>Color_Diff: originalcolor -= (255 - img.getpixel((i,j)))//2 new.putpixel((i,j),originalcolor) qcolor = sum([img.getpixel((i, j - r)) for r in range(pen_size)]) // pen_size wcolor = sum([img.getpixel((i , j+r)) for r in range(pen_size)]) // pen_size if abs(qcolor - wcolor) > Color_Diff: originalcolor -= (255 - img.getpixel((i, j))) // 2 new.putpixel((i, j), originalcolor) new.save('img_tony.jpg') os.system('mshta vbscript:createobject("sapi.spvoice").speak("%s")(window.close)'%'您的人物绘画已经完成') os.system("img_tony.jpg")