from wordcloud import WordCloud from tkinter import TkButtonLabelEntryStringVarEND from jieba import cut from time import localtime from PIL import Image from numpy import array
‘‘‘ 本软件由个人研发,如有雷同纯属巧合‘‘‘
#文本路径用r‘%s‘ % (用户输入)来获取 font = r‘C:\Windows\Fonts\simkai.ttf‘#字体路径(配置中文词云) def cy(in_文本路径in_图片路径in_输出路径in_背景颜色in_大小): ‘‘‘ cy(in_文本路径in_图片路径in_输出路径in_背景颜色in_大小) 通过指定参数来生成自定义的词云 ‘‘‘ if in_图片路径 == ‘默认‘: text = ‘ ‘.join(cut(str(open(in_文本路径‘r‘encoding=‘gbk‘).read()))) wordcloud = WordCloud(background_color=in_背景颜色font_path=fontwidth=int(str(in_大小).split(‘x‘)[0])height=int(str(in_大小).split(‘x‘)[1])) wordcloud.generate(text) wordcloud.to_file(in_输出路径) else: text = ‘ ‘.join(cut(str(open(in_文本路径‘r‘encoding=‘gbk‘).read()))) photo = Image.open(in_图片路径) photoarray = array(photo) wordcloud = WordCloud(background_color=in_背景颜色font_path=fontmask=photoarray)
评论
共有 条评论