// see https://github.com/defnull/pixelflut package main import ( "bytes" "flag" "fmt" "image" "image/color" "math/rand" "net" "os" _ "image/gif" _ "image/jpeg" _ "image/png" ) const defaultServer = `151.217.15.90:1337` // 37c3 func main() { var ( xoff, yoff, samples int shuf bool server string ) flag.IntVar(&xoff, "xoff", 0, "X-coordinate offset") flag.IntVar(&yoff, "yoff", 0, "Y-coordinate offset") flag.IntVar(&samples, "samples", 1, "Samples of randomised buffers") flag.BoolVar(&shuf, "shuf", false, "Shuffle order of pixels") flag.StringVar(&server, "serv", defaultServer, "Server IP and port") flag.Parse() if flag.NArg() != 1 { fmt.Println("This command takes one .png file as an argument") os.Exit(1) } f, err := os.Open(flag.Arg(0)) if err != nil { fmt.Println(err) os.Exit(1) } img, _, err := image.Decode(f) if err != nil { fmt.Println(err) os.Exit(1) } var buf bytes.Buffer for i := 0; i < samples; i++ { var lines []string for y := img.Bounds().Min.Y; y <= img.Bounds().Max.Y; y++ { for x := img.Bounds().Min.X; x <= img.Bounds().Max.X; x++ { rgba := color.RGBAModel.Convert(img.At(x, y)).(color.RGBA) var line string if rgba.A == 255 { line = fmt.Sprintf("PX %d %d %02x%02x%02x\n", xoff+x, yoff+y, rgba.R, rgba.G, rgba.B) } else if rgba.A > 0 { line = fmt.Sprintf("PX %d %d %02x%02x%02x%02x\n", xoff+x, yoff+y, rgba.R, rgba.G, rgba.B, rgba.A) } lines = append(lines, line) } } if shuf { rand.Shuffle(len(lines), func(i, j int) { lines[i], lines[j] = lines[j], lines[i] }) } for l := 0; l < len(lines); l++ { fmt.Fprintf(&buf, lines[l]) } } conn, err := net.Dial("tcp", server) if err != nil { fmt.Println(err) os.Exit(1) } data := buf.Bytes() for { conn.Write(data) } }