Example #1
0
func (this *AsciiImg) Do(w, h int) string {
	ascii := ""

	if this.img == nil {
		return ascii
	}

	rows := int(math.Ceil(float64(this.img.Bounds().Dy()) / float64(h)))
	cols := int(math.Ceil(float64(this.img.Bounds().Dx()) / float64(w)))

	for r := 0; r < rows; r++ {
		for c := 0; c < cols; c++ {
			x, y := c*w, r*h

			avg := this.getBlockInfo(x, y, w, h)
			ascii += string(gray.Get("default", avg))
		}
		ascii += "\r\n"
	}

	return ascii
}
Example #2
0
func (this *AsciiImg) DoByCol(cols int) string {
	ascii := ""

	if this.img == nil {
		return ascii
	}

	w := this.img.Bounds().Dx() / cols
	h := w * 2
	rows := this.img.Bounds().Dy() / h

	for r := 0; r < rows; r++ {
		for c := 0; c < cols; c++ {
			x, y := c*w, r*h

			avg := this.getBlockInfo(x, y, w, h)
			ascii += string(gray.Get("default", avg))
		}
		ascii += "\r\n"
	}

	return ascii
}