Exemple #1
0
// getStreams opens ands returns the input and output streams.
func getImages(input string) (draw.Image, draw.Image) {
	var fd io.ReadCloser
	var err error

	if len(input) == 0 {
		fd = os.Stdin
	} else {
		fd, err = os.Open(input)
		defer fd.Close()
	}

	if err != nil {
		fmt.Fprintf(os.Stderr, "Open input file: %v\n", err)
		os.Exit(1)
	}

	img, _, err := lib.Decode(fd)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Decode image: %v\n", err)
		os.Exit(1)
	}

	dimg, ok := img.(draw.Image)
	if !ok {
		fmt.Fprintf(os.Stderr, "Decode image: %T is not draw.Image; missing Set method.\n", img)
		os.Exit(1)
	}

	return dimg, image.NewRGBA(img.Bounds())
}
Exemple #2
0
// load loads the given image.
func load(input string) image.Image {
	var fd io.ReadCloser
	var err error

	if len(input) == 0 {
		fd = os.Stdin
	} else {
		fd, err = os.Open(input)
		defer fd.Close()
	}

	if err != nil {
		fmt.Fprintf(os.Stderr, "Open input file: %v\n", err)
		os.Exit(1)
	}

	img, _, err := lib.Decode(fd)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Decode image: %v\n", err)
		os.Exit(1)
	}

	return img
}