Skip to content

Instantly share code, notes, and snippets.

@YHaruoka
Created May 25, 2022 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YHaruoka/099e3da16fcb2beb40b88b03d2cd9117 to your computer and use it in GitHub Desktop.
Save YHaruoka/099e3da16fcb2beb40b88b03d2cd9117 to your computer and use it in GitHub Desktop.
from PIL import Image
import numpy as np
from wordcloud import WordCloud
import matplotlib.pyplot as plt
mask_array = np.array(Image.open('mask.png'))
text = open("test.txt",encoding='utf-8').read()
wordcloud_mask = WordCloud(mask=mask_array, background_color="white", max_font_size=250).generate(text)
wordcloud_mask.to_file("word_cloud_mask_result.png")
wordcloud_mask_contour = WordCloud(mask=mask_array, contour_width=5, contour_color="steelblue", background_color="white", max_font_size=250).generate(text)
wordcloud_mask_contour.to_file("word_cloud_mask_contour_result.png")
# plt.imshow(wordcloud_mask)
plt.imshow(wordcloud_mask_contour)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment