https://github.com/psykhi/wordclouds
Wordclouds in go
https://github.com/psykhi/wordclouds
algorithm go golang image wordcloud
Last synced: 1 day ago
JSON representation
Wordclouds in go
- Host: GitHub
- URL: https://github.com/psykhi/wordclouds
- Owner: psykhi
- License: apache-2.0
- Created: 2018-05-23T18:40:13.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-14T19:01:59.000Z (over 2 years ago)
- Last Synced: 2024-06-18T17:14:26.899Z (over 1 year ago)
- Topics: algorithm, go, golang, image, wordcloud
- Language: Go
- Size: 3.44 MB
- Stars: 60
- Watchers: 4
- Forks: 23
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Wordclouds in go.

# How to use
```go
wordCounts := map[string]int{"important":42, "noteworthy":30, "meh":3}
w := wordclouds.NewWordcloud(
wordCounts,
wordclouds.FontFile("fonts/myfont.ttf"),
wordclouds.Height(2048),
wordclouds.Width(2048),
)
img := w.Draw()
```
# Options
- Output height and width
- Font: Must be a valid TTF file.
- Font max,min size
- Colors
- Background color
- Placement : random or circular
- Masking
# Masking
A list of bounding boxes where the algorithm can not place words can be provided.
The `Mask` function can be used to create such a mask given a file and a masking color.
```go
boxes := wordclouds.Mask(
conf.Mask.File,
conf.Width,
conf.Height,
conf.Mask.Color,
)
```
See the example folder for a fully working implementation.
# Speed
Most wordclouds should take a few seconds to be generated. A spatial hashmap is used to find potential collisions.
There are two possible placement algorithm choices:
1. Random: the algorithms randomly tries to place the word anywhere in the image space.
- If it can't find a spot after 500000 tries, it gives up and moves on to the next word. It's quite slow.
2. Spiral: the algorithm starts to place the words on concentric circles starting at the center of the image.
It is very fast and is the default algorithm
# Contributing
Feel free to create pull requests, I'll gladly review them!