avif/example_test.go

43 lines
736 B
Go
Raw Normal View History

2019-03-17 12:13:37 +00:00
package avif_test
import (
"image"
_ "image/jpeg"
"log"
"os"
"github.com/Kagami/go-avif"
)
2019-03-17 17:52:27 +00:00
const usageHelp = "Usage: %s src.jpg dst.avif"
func Example() {
2019-03-17 12:13:37 +00:00
if len(os.Args) != 3 {
2019-03-17 17:52:27 +00:00
log.Fatalf(usageHelp, os.Args[0])
2019-03-17 12:13:37 +00:00
}
srcPath := os.Args[1]
src, err := os.Open(srcPath)
if err != nil {
log.Fatalf("Can't open sorce file: %v", err)
}
dstPath := os.Args[2]
dst, err := os.Create(dstPath)
if err != nil {
log.Fatalf("Can't create destination file: %v", err)
}
img, _, err := image.Decode(src)
if err != nil {
2019-03-17 12:28:20 +00:00
log.Fatalf("Can't decode source file: %v", err)
2019-03-17 12:13:37 +00:00
}
err = avif.Encode(dst, img, nil)
if err != nil {
log.Fatalf("Can't encode source image: %v", err)
}
log.Printf("Encoded AVIF at %s", dstPath)
}