文本1.txt + 图9.jpg
from wordcloud import WordCloud from scipy.misc import imread font = r'C:WindowsFontssimfang.ttf' f = open('1.txt','r',encoding='utf-8').read() mk = imread('9.jpg') wc = WordCloud( mask = mk, font_path=font, background_color='white', width =800, height = 600, margin=2 ).generate(f) wc.to_file('1.jpg')
9.jpg
1.jpg