Skip to content

Commit

Permalink
Fixed bug for generating images with transparent background.
Browse files Browse the repository at this point in the history
The contour used was lacking a transparency channel.
  • Loading branch information
m000 committed Jun 5, 2018
1 parent c6a5853 commit da71700
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions wordcloud/wordcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,12 +715,16 @@ def _draw_contour(self, img):
contour = Image.fromarray(contour)
contour = contour.filter(ImageFilter.GaussianBlur(radius=radius))
contour = np.array(contour) > 0
contour = np.dstack((contour, contour, contour))
if img.mode == 'RGBA':
contour = np.dstack((contour, contour, contour, contour))
else:
contour = np.dstack((contour, contour, contour))

# color the contour
ret = np.array(img) * np.invert(contour)
if self.contour_color != 'black':
color = Image.new(img.mode, img.size, self.contour_color)

if self.contour_color is not None:
color = np.array(Image.new(img.mode, img.size, self.contour_color))
ret += np.array(color) * contour

return Image.fromarray(ret)

0 comments on commit da71700

Please sign in to comment.