From 7bdfbedde14a21382440fbba8e65dc139c46b9f2 Mon Sep 17 00:00:00 2001 From: Antonia Rescribe Date: Mon, 30 Aug 2021 12:49:23 +0100 Subject: adjusted the height of the image in the pdf to 1000px if the smaller option is chosen --- pdf.go | 8 ++++++-- 1 file 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 -- cgit v1.2.1-24-ge1ad