You can create a logo with just word. The module to use is "wordcloud". Then create a mask of the logo (black and white shape).
Why would you want to do this? Just for fun. You can take any list of words and any logo that is a black and white mask.
Lets say the windows logo:
Generate a logo with Python
As said before need several things:
- any font, say SimHei
- mask (black and white)
- word list
- the program below
- modules installed (matplotlib, wordcloud). You can do that with pip
The mask:
You will need a list of words. I use the dictionary available on Ubuntu Linux, but any word list will do. The list of words should be less than 5000 words.
Run the program below to create the logo:
#!/usr/bin/python3
from wordcloud import WordCloud
import numpy as np
from PIL import Image
import os
with open('/usr/share/dict/american-english') as f:
wordList = f.read().splitlines()
text = " ".join(wordList)
print(text)
src_dir = os.getcwd()
imagePath = src_dir + "/apple.png"
font = src_dir + "/SimHei.ttf"
resultPath = src_dir + "/output.png"
bg = np.array(Image.open(imagePath))
wc = WordCloud(
mask=bg,
background_color="white",
max_font_size=150,
min_font_size=5,
max_words=5000,
random_state=40,
font_path=font,
).generate(text)
wc.to_file(resultPath)
Output:
Learn Python:
Top comments (0)