Exemplo n.º 1
0
func main() {
	var linecount int
	var line []byte
	var err error

	file, expr := parseArgs()
	src, dst := getImages(file)

	for err != io.EOF {
		linecount++
		line, err = expr.ReadBytes('\n')

		if err != nil && err != io.EOF {
			fmt.Fprintf(os.Stderr, "Read expression: %v\n", err)
			os.Exit(1)
		}

		ok, err := maplib.Parse(line, src, dst)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Line %d: %v\n", linecount, err)
		}

		if ok {
			src, dst = dst, src
		}
	}

	err = lib.Encode(os.Stdout, "png", src, "")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Write output image: %v\n", err)
		os.Exit(1)
	}
}
Exemplo n.º 2
0
// save encodes the given image as PNG and saves it to stdout.
func save(img image.Image) {
	err := lib.Encode(os.Stdout, "png", img, "")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Encode image: %v\n", err)
		os.Exit(1)
	}
}
Exemplo n.º 3
0
func main() {
	file, format, options := parseArgs()
	in, out := getStreams(file)

	img, _, err := image.Decode(in)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Invalid input file: %v\n", err)
		return
	}

	err = lib.Encode(out, format, img, options)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Encode failed: %v\n", err)
		return
	}
}