Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

farsi-wordcloud

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

farsi-wordcloud

A package to generate Farsi word clouds with proper text rendering.

  • 0.1.0
  • PyPI
  • Socket score

Maintainers
1

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:

  • matplotlib
  • wordcloud
  • arabic_reshaper
  • bidi

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.json file.
  • 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.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc