Improve BMP generation
This commit is contained in:
parent
c8c84dcb52
commit
d32aadcc4d
3 changed files with 24 additions and 10 deletions
|
@ -2,7 +2,7 @@ FROM golang:latest
|
|||
|
||||
RUN apt-get update -qq && apt-get install -y netcat
|
||||
RUN apt-get install -y -q libsm6 libcups2 libcairo2 libdbus-1-3 libxinerama1
|
||||
RUN apt-get install -y texlive-latex-extra poppler-utils
|
||||
RUN apt-get install -y texlive-latex-extra texlive-fonts-extra poppler-utils
|
||||
|
||||
## Download pandoc
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
---
|
||||
fontfamily: libertinus
|
||||
fontfamilyoptions:
|
||||
- osf
|
||||
- p
|
||||
fontfamily: dejavu
|
||||
#fontfamilyoptions:
|
||||
#- osf
|
||||
#- p
|
||||
#fontsize: 14pt
|
||||
papersize: a6
|
||||
fontsize: 12pt
|
||||
geometry:
|
||||
- top=5mm
|
||||
- left=5mm
|
||||
|
|
|
@ -53,7 +53,7 @@ var funcmap = template.FuncMap{
|
|||
},
|
||||
}
|
||||
|
||||
func convertPDFToPNG(filename string) error {
|
||||
func convertPDFToBMP(filename string) error {
|
||||
out, err := exec.Command("pdftoppm", filename, "./data/screen", "-png").CombinedOutput()
|
||||
if string(out) != "" {
|
||||
return fmt.Errorf("pdftoppm: %s", string(out))
|
||||
|
@ -61,6 +61,20 @@ func convertPDFToPNG(filename string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out, err = exec.Command("convert", "./data/screen-1.png",
|
||||
"-rotate", "-90",
|
||||
"-resize", "800x480!",
|
||||
"-dither", "none",
|
||||
"-remap", "./data/palette.gif",
|
||||
"BMP3:./data/screen.bmp",
|
||||
).CombinedOutput()
|
||||
if string(out) != "" {
|
||||
return fmt.Errorf("covert: %s", string(out))
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -93,14 +107,14 @@ func serveScreen(res http.ResponseWriter, req *http.Request) {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
log.Println("Converting pdf to png.")
|
||||
err = convertPDFToPNG("./data/screen.pdf")
|
||||
log.Println("Converting PDF to monochrome BMP.")
|
||||
err = convertPDFToBMP("./data/screen.pdf")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
log.Println("Serving screen.png...")
|
||||
http.ServeFile(res, req, "./data/screen-1.png")
|
||||
http.ServeFile(res, req, "./data/screen.bmp")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
Loading…
Reference in a new issue