我的代码出错了,哪位大神可以帮帮我
# coding:utf-8
# Python 实用宝典
# 2021/01/22
def transform_format(val):
if val[0] > 245 and val[1] > 245 and val[2] > 245:
val[0] = val[1] = val[2] = 255
return val
else:
return val
def gen_happy_birthday_cloud(file, name):
' words'.add('生日快乐', 10)
' words'.add('田普旭', 12)
for i in range(1000):
'words'.add('生日', numpy.random.randint(1, 5))
'words'.add('快乐', numpy.random.randint(1, 5))
'words'.add('田普旭', numpy.random.randint(1, 5))
bimg = imread(file)
for color in range(len(bimg)):
bimg[color] = list(map(transform_format, bimg[color]))
wordcloud = WordCloud(
background_color='white', mask=bimg,
font_path='simhei.ttf'
).generate_from_frequencies(words)
bimgColors = ImageColorGenerator(bimg)
plt.axis("off")
plt.imshow(wordcloud.recolor(color_func=bimgColors))
plt.savefig(name+'.png')
plt.show()
gen_happy_birthday_cloud('p2.png', '宝典哥')