Skip to content

Instantly share code, notes, and snippets.

@trashhalo
Created October 22, 2020 00:53
Show Gist options
  • Save trashhalo/6154a690bd2612ae33c8252d8051eb9f to your computer and use it in GitHub Desktop.
Save trashhalo/6154a690bd2612ae33c8252d8051eb9f to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"errors"
"fmt"
"image"
"net/http"
"os"
"github.com/qeesung/image2ascii/convert"
)
func main() {
in := bufio.NewScanner(os.Stdin)
for in.Scan() {
line := in.Text()
err := convertLineToArt(line)
if err != nil {
panic(err)
}
}
}
func convertLineToArt(line string) error {
fmt.Println(line)
resp, err := http.Get(line)
if err != nil {
return err
}
defer resp.Body.Close()
img, _, err := image.Decode(resp.Body)
if err != nil && errors.Is(err, image.ErrFormat) {
return nil
} else if err != nil {
return err
}
convertOptions := convert.DefaultOptions
convertOptions.FixedWidth = 50
convertOptions.FixedHeight = 50
converter := convert.NewImageConverter()
for _, row := range converter.Image2ASCIIMatrix(img, &convertOptions) {
fmt.Print(row)
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment