V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
bangbaoshi
V2EX  ›  问与答

golang 语言实现文字云算法

  •  
  •   bangbaoshi · 2018-05-04 11:42:46 +08:00 · 995 次点击
    这是一个创建于 2207 天前的主题,其中的信息可能已经有所发展或是发生改变。

    golang 版本的文字云算法实现

    一直以来,都是通过 golang 进行后端开发,后来觉得 golang 可以做点其他有意思的玩意,后来用了 golang 实现了文字云算法,后续开放其他语言版本

    项目地址

    https://github.com/bangbaoshi/wordcloud

    效果图

    测试步骤如下

    git clone https://github.com/bangbaoshi/wordcloud.git
    
    cd wordcloud
    
    go run boot/main.go
    
    

    通过以上三步即可在 imgs 目录中生成文字云图片(查看 imgs/out.png)

    目录介绍

    1. boot 目录包含测试用例
    2. fonts 目录包含若干种字体(非商业使用)
    3. imgs 目录包含模板图片,文字云生成的效果图就是按照模板图片的样子来生成

    使用说明

    boot/main.go 中已经简单介绍了使用方法

    package main
    
    import (
    	"image/color"
    	"github.com/bangbaoshi/wordcloud"
    )
    
    func renderNow() {
    	//需要写入的文本数组
    	textList := []string{"恭喜", "发财", "万事", "如意"}
    	//文本角度数组
    	angles := []int{0, 15, -15, 90}
    	//文本颜色数组
    	colors := []*color.RGBA{
    		&color.RGBA{0x0, 0x60, 0x30, 0xff},
    		&color.RGBA{0x60, 0x0, 0x0, 0xff},
    		&color.RGBA{0x73, 0x73, 0x0, 0xff},
    	}
    	//设置对应的字体路径,和输出路径
    	render := wordcloud_go.NewWordCloudRender(60, 8,
    		"./fonts/xin_shi_gu_yin.ttf",
    		"./imgs/tiger.png", textList, angles, colors, "./imgs/out.png")
    	//开始渲染
    	render.Render()
    }
    
    func main() {
    	renderNow()
    }
    
    
    

    项目介绍

    1. 使用 golang 语言实现了文字云算法
    2. 用 golang 实现一些有趣的想法
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1059 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:22 · PVG 02:22 · LAX 11:22 · JFK 14:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.