A package to generate Farsi word clouds with proper text rendering.
Project description
FarsiWordCloud README
Overview
The FarsiWordCloud class is a specialized extension of the Fonts class designed to generate word clouds in Farsi (Persian) text. It handles text reshaping and bidirectional text rendering to ensure that Farsi text is correctly displayed in the word cloud.
Installation
To use the FarsiWordCloud class, you need to have the following libraries installed:
matplotlibwordcloudarabic_reshaperbidi
You can install these libraries using pip:
pip install matplotlib wordcloud arabic-reshaper python-bidi
Usage
Here is an example of how to use the FarsiWordCloud class:
from FarsiWordCloud import FarsiWordCloud
# Sample text in Farsi
text = "سلام این یک تست برای ایجاد واژهابری است."
# Create an instance of FarsiWordCloud
wordcloud = FarsiWordCloud(
text=text,
font_name="BYekan", # Specify the font name from the available fonts
width=800,
height=400,
background_color='white',
max_font_size=250,
min_font_size=10
)
# Generate the word cloud
wordcloud.generate_wordcloud()
# Display the word cloud
wordcloud.show_wordcloud()
# Save the word cloud to a file
wordcloud.save_wordcloud(filename='farsi_wordcloud.png')
Methods
- text: The Farsi text to be used for generating the word cloud.
- font_name: The name of the font to be used. This should be one of the fonts listed in the
info.jsonfile. - width: The width of the word cloud image (in pixels).
- height: The height of the word cloud image (in pixels).
- background_color: The background color of the word cloud.
- max_font_size: The maximum font size for the words in the word cloud.
- min_font_size: The minimum font size for the words in the word cloud.
reshape_text(self)
Reshapes and reorders the Farsi text to ensure correct display. This method uses the arabic_reshaper library to reshape the text and the bidi library to handle bidirectional text.
generate_wordcloud(self)
Generates the word cloud from the reshaped text. This method creates a WordCloud object with the specified parameters and generates the word cloud image.
show_wordcloud(self)
Displays the generated word cloud using matplotlib. If the word cloud has not been generated yet, this method will call generate_wordcloud() first.
save_wordcloud(self, filename='wordcloud.png')
Saves the generated word cloud to a file. The default filename is wordcloud.png, but you can specify a different filename if desired.
Fonts
The FarsiWordCloud class relies on a set of fonts specified in the fonts/info.json file. Ensure that the font files listed in this file are available in the fonts/files/ directory.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file farsi_wordcloud-0.1.0.tar.gz.
File metadata
- Download URL: farsi_wordcloud-0.1.0.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16f260939fa1a40b5d1e916cdbe30bc008cbfd2a5e3ca9a505797eb6c80a5dee
|
|
| MD5 |
d32b0a4cb63ebb666d0d4bb3858cd8f2
|
|
| BLAKE2b-256 |
321f0897e7802608f370562868ffa69c5c37da95eadde7c357df247ce5384315
|
File details
Details for the file farsi_wordcloud-0.1.0-py3-none-any.whl.
File metadata
- Download URL: farsi_wordcloud-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a64a52dbd8fc1e190358fb7ad547cbe36aab81c2542964a26b07ddc1e2c6549
|
|
| MD5 |
fadad17e2efc9d8c6919b602e13409b9
|
|
| BLAKE2b-256 |
d9ec656e1e398c0472dc9a3043adf60fc9950d72133f868c22e108d700c41800
|