package util

import (
	"image"
	"image/png"
	"os"
)

// ProcessImage takes input png image from stdin, processes it with f and outputs it to stdout.
func ProcessStdio(f func(image.Image) image.Image) error {
	img, err := png.Decode(os.Stdin)
	if err != nil {
		return err
	}
	err = png.Encode(os.Stdout, f(img))
	if err != nil {
		return err
	}
	return err
}
