1 个不稳定版本
| 0.1.0 | 2023年9月6日 |
|---|
#691 in 图像
6.5MB
1K SLoC

wcloud
支持遮罩、自定义字体、自定义着色函数等,生成美观的词云。
安装
目前,安装 wcloud 的唯一方法是安装 Rust 和使用 Cargo。
cargoinstall wcloud
用法
wcloud 可以用作命令行应用程序和库。
命令行
二进制文件以 wcloud 的名称运行。唯一的必需输入是用于生成词云的文本,可以通过 --text 标志或通过 stdin 提供。
$wcloud --文本file.txt -ocloud.png
$echo'云朵很棒!' | wcloud --输出cloud.png
要查看所有选项列表,请使用 wcloud --help。
库
wcloud 也可以用作 Rust crate。使用 cargo add wcloud 添加它作为依赖项。文档可在 此处 查找。
以下是一个基本示例
use wcloud::{WordCloud, WordCloudSize};
fn main() {
let text = r#"
An arcus cloud is a low, horizontal cloud formation,
usually appearing as an accessory cloud to a cumulonimbus.
Roll clouds and shelf clouds are the two main types of arcus
clouds. They most frequently form along the leading edge or
gust fronts of thunderstorms; some of the most dramatic arcus
formations mark the gust fronts of derecho-producing convective
systems. Roll clouds may also arise in the absence of
thunderstorms, forming along the shallow cold air currents of
some sea breeze boundaries and cold fronts.
"#;
let wordcloud = WordCloud::default()
.with_rng_seed(0);
let size = WordCloudSize::FromDimensions { width: 1000, height: 500 };
let wordcloud_image = wordcloud.generate_from_text(text, size, 1.0);
wordcloud_image.save("cloud.png")
.expect("Unable to save image");
}

在 examples/ 目录中可以找到使用遮罩、自定义颜色和其他功能生成词云的示例。
画廊
鸣谢
该项目主要基于 word_cloud 项目,由 @amueller 提供。相比之下,wcloud 缺少以下功能
- 颜色遮罩
- 遮罩轮廓
- 双词组
- 颜色图
- 复数归一化
许可证
wcloud 在 MIT 许可证 下发布。默认的 Ubuntu 字体包含在 Ubuntu 字体许可证 下,而 Droid Sans Mono 在 Apache License 2 下。
依赖项
~29MB
~505K SLoC