summaryrefslogtreecommitdiff
path: root/pdf.go
diff options
context:
space:
mode:
authorAntonia Rescribe <antonia@rescribe.xyz>2021-08-30 12:49:23 +0100
committerNick White <git@njw.name>2021-08-30 12:49:23 +0100
commit7bdfbedde14a21382440fbba8e65dc139c46b9f2 (patch)
treeec766e2364c70e9f091b6f97e9a1d95372ebfb89 /pdf.go
parenteea92760c9f9f2fa108cf759f2b4ca17b57e8364 (diff)
adjusted the height of the image in the pdf to 1000px if the smaller option is chosen
Diffstat (limited to 'pdf.go')
-rw-r--r--pdf.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/pdf.go b/pdf.go
index eb5f021..2287ba9 100644
--- a/pdf.go
+++ b/pdf.go
@@ -24,7 +24,6 @@ import (
// TODO: maybe set this in Fpdf struct
const pageWidth = 5.8 // pageWidth in inches - 5.8" is A5
-const scaleSmaller = 3 // amount the width and height are divided by
// pxToPt converts a pixel value into a pt value (72 pts per inch)
// This uses pageWidth to determine the appropriate value
@@ -83,9 +82,14 @@ func (p *Fpdf) AddPage(imgpath, hocrpath string, smaller bool) error {
if err != nil {
return errors.New(fmt.Sprintf("Could not decode image: %v", err))
}
+
+ const smallerImgHeight = 1000
+
b := img.Bounds()
+
+ smallerImgWidth := b.Max.X*smallerImgHeight/b.Max.Y
if smaller {
- r := image.Rect(0, 0, b.Max.X/scaleSmaller, b.Max.Y/scaleSmaller)
+ r := image.Rect(0, 0, smallerImgWidth, smallerImgHeight)
smimg := image.NewRGBA(r)
draw.ApproxBiLinear.Scale(smimg, r, img, b, draw.Over, nil)
img = smimg