summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2021-08-30 13:07:43 +0100
committerNick White <git@njw.name>2021-08-30 13:07:43 +0100
commit37a1581288447ca63412047fec0fb081043ba6fb (patch)
tree30ec74575d81ed4a1f349507604c6187bf8e5b87
parent7bdfbedde14a21382440fbba8e65dc139c46b9f2 (diff)
pdf: Always encode images as jpegv0.5.1
Previously for PDFs using binarised images we kept them as PNG, but there's no good reason to do so, it's better to just get the space savings on offer from jpeg.
-rw-r--r--pdf.go12
1 files changed, 4 insertions, 8 deletions
diff --git a/pdf.go b/pdf.go
index 2287ba9..6543e35 100644
--- a/pdf.go
+++ b/pdf.go
@@ -12,7 +12,7 @@ import (
"html"
"image"
"image/jpeg"
- "image/png"
+ _ "image/png"
"io/ioutil"
"os"
@@ -78,7 +78,7 @@ func (p *Fpdf) AddPage(imgpath, hocrpath string, smaller bool) error {
if err != nil {
return errors.New(fmt.Sprintf("Could not open file %s: %v", imgpath, err))
}
- img, imgtype, err := image.Decode(imgf)
+ img, _, err := image.Decode(imgf)
if err != nil {
return errors.New(fmt.Sprintf("Could not decode image: %v", err))
}
@@ -96,18 +96,14 @@ func (p *Fpdf) AddPage(imgpath, hocrpath string, smaller bool) error {
}
var buf bytes.Buffer
- if imgtype == "jpeg" {
- err = jpeg.Encode(&buf, img, &jpeg.Options{Quality: jpeg.DefaultQuality})
- } else {
- err = png.Encode(&buf, img)
- }
+ err = jpeg.Encode(&buf, img, &jpeg.Options{Quality: jpeg.DefaultQuality})
if err != nil {
return err
}
p.fpdf.AddPageFormat("P", gofpdf.SizeType{Wd: pxToPt(b.Dx()), Ht: pxToPt(b.Dy())})
- _ = p.fpdf.RegisterImageOptionsReader(imgpath, gofpdf.ImageOptions{ImageType: imgtype}, &buf)
+ _ = p.fpdf.RegisterImageOptionsReader(imgpath, gofpdf.ImageOptions{ImageType: "jpeg"}, &buf)
p.fpdf.ImageOptions(imgpath, 0, 0, pxToPt(b.Dx()), pxToPt(b.Dy()), false, gofpdf.ImageOptions{}, 0, "")
p.fpdf.SetTextRenderingMode(3)