Files
orientator/cmd/testfixture/main.go
2026-05-13 19:52:51 +03:00

42 lines
765 B
Go

// testfixture renders page 1 of a PDF as upright PNG and as a 90°-rotated PNG.
package main
import (
"fmt"
"image"
"image/png"
"os"
"github.com/gen2brain/go-fitz"
"orientator/internal/pipeline"
)
func main() {
if len(os.Args) < 4 {
fmt.Println("usage: testfixture <in.pdf> <upright.png> <rotated90.png>")
os.Exit(2)
}
doc, err := fitz.New(os.Args[1])
must(err)
defer doc.Close()
img, err := doc.ImageDPI(0, 150)
must(err)
writePNG(os.Args[2], img)
writePNG(os.Args[3], pipeline.RotateImage(img, 90))
fmt.Println("ok")
}
func writePNG(path string, img image.Image) {
f, err := os.Create(path)
must(err)
defer f.Close()
must(png.Encode(f, img))
}
func must(err error) {
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}