Commit 642b4b5c authored by Andreas Mueller's avatar Andreas Mueller
Browse files

Merge pull request #36 from tonsh/transparent_bg

Add mode argument, transparent background can be generated
parents 05c3e694 d1ac0c73
......@@ -91,6 +91,9 @@ class WordCloud(object):
max_font_size : int or None (default=None)
Maximum font size for the largest word. If None, height of the image is
mode: string (default="RGB")
Transparent background will be generated when mode is "RGBA" and
background_color is None.
......@@ -114,7 +117,8 @@ class WordCloud(object):
def __init__(self, font_path=None, width=400, height=200, margin=5,
ranks_only=False, prefer_horizontal=0.9, mask=None, scale=1,
color_func=random_color_func, max_words=200, stopwords=None,
random_state=None, background_color='black', max_font_size=None):
random_state=None, background_color='black', max_font_size=None,
if stopwords is None:
stopwords = STOPWORDS
if font_path is None:
......@@ -137,6 +141,7 @@ class WordCloud(object):
if max_font_size is None:
max_font_size = height
self.max_font_size = max_font_size
self.mode = mode
def fit_words(self, frequencies):
"""Create a word_cloud from words and frequencies.
......@@ -375,7 +380,8 @@ class WordCloud(object):
height, width = self.height, self.width
img ="RGB", (width * self.scale, height * self.scale), self.background_color)
img =, (width * self.scale, height * self.scale),
draw = ImageDraw.Draw(img)
for (word, count), font_size, position, orientation, color in self.layout_:
font = ImageFont.truetype(self.font_path, font_size * self.scale)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment