当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 14

MicroOS / pic2ascii
暂停

forked from wzshiming / pic2ascii
暂停
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
to_ascii.go 677 Bytes
一键复制 编辑 原始数据 按行查看 历史
wzshiming 提交于 2018-01-01 23:26 . clear
package pic2ascii
import (
"image"
"image/color"
)
const (
max = 1<<16 - 1
)
// Image to Ascii
func ToAscii(m image.Image, chars []rune, prefix, suffix []rune) []rune {
bounds := m.Bounds()
dx := bounds.Dx()
dy := bounds.Dy()
t := max / (len(chars) - 1)
dst := make([]rune, 0, (dy * (dx + len(prefix) + len(suffix))))
for i := 0; i != dy; i++ {
if len(prefix) != 0 {
dst = append(dst, prefix...)
}
for j := 0; j != dx; j++ {
cr := m.At(j, i)
g, _, _, _ := color.GrayModel.Convert(color.NRGBAModel.Convert(cr)).RGBA()
ii := int(g) / t
dst = append(dst, chars[ii])
}
if len(suffix) != 0 {
dst = append(dst, suffix...)
}
}
return dst
}
Go
1
https://gitee.com/MicroOS/pic2ascii.git
git@gitee.com:MicroOS/pic2ascii.git
MicroOS
pic2ascii
pic2ascii
master

搜索帮助