Created
October 22, 2020 00:53
-
-
Save trashhalo/6154a690bd2612ae33c8252d8051eb9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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