From 40c1e4956c0f4cd2c5f139aba7cb7bc04c57fc0f Mon Sep 17 00:00:00 2001 From: Nick White Date: Fri, 25 Jan 2019 17:26:43 +0000 Subject: Add html output including all images, by writing them to an html directory --- avg-lines/html.go | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 avg-lines/html.go (limited to 'avg-lines/html.go') diff --git a/avg-lines/html.go b/avg-lines/html.go new file mode 100644 index 0000000..f299830 --- /dev/null +++ b/avg-lines/html.go @@ -0,0 +1,61 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + + "rescribe.xyz/go.git/lib/line" +) + +func copylineimg(fn string, l line.Detail) error { + f, err := os.Create(fn) + if err != nil { + return err + } + defer f.Close() + + return l.Img.CopyLineTo(f) +} + +func htmlout(dir string, lines line.Details) error { + err := os.MkdirAll(dir, 0700) + if err != nil { + return err + } + + fn := filepath.Join(dir, "index.html") + f, err := os.Create(fn) + if err != nil { + return err + } + defer f.Close() + + _, err = fmt.Fprintf(f, "" + + "\n\n") + if err != nil { + return err + } + for _, l := range lines { + fn = filepath.Base(l.OcrName) + "_" + l.Name + ".png" + err = copylineimg(filepath.Join(dir, fn), l) + if err != nil { + return err + } + _, err = fmt.Fprintf(f, "\n" + + "\n" + + "\n" + + "\n" + + "\n", + l.Avgconf, l.OcrName, l.Name, fn, l.Text) + if err != nil { + return err + } + } + _, err = fmt.Fprintf(f, "

%.4f%%

%s %s
%s
\n\n") + if err != nil { + return err + } + + return nil +} -- cgit v1.2.1-24-ge1ad