golang實現文字雲算法

golang實現文字雲算法

項目連接

https://github.com/bangbaoshi/wordcloudgit

效果圖


測試步驟以下

git clone https://github.com/bangbaoshi/wordcloud.git

cd wordcloud

go run boot/main.go

經過以上三步便可在imgs目錄中生成文字雲圖片(查看imgs/out.png)github

目錄介紹

  1. boot目錄包含測試用例
  2. fonts目錄包含若干種字體(非商業使用)
  3. imgs目錄包含模板圖片,文字雲生成的效果圖就是按照模板圖片的樣子來生成

使用說明

boot/main.go中已經簡單介紹了使用方法golang

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實現一些有趣的想法
相關文章
相關標籤/搜索