From 784dacec868d6befa2cfd68db03306de24095654 Mon Sep 17 00:00:00 2001 From: kentquirk Date: Mon, 7 Mar 2016 14:46:05 -0500 Subject: Support reading and/or setting image dpi Adds the ability to support reading dpi from PNG images, and setting dpi on any image directly; this allows images to be displayed at the designed size. --- def.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'def.go') diff --git a/def.go b/def.go index 4c99733..d3eaca0 100644 --- a/def.go +++ b/def.go @@ -71,6 +71,7 @@ type ImageInfoType struct { dp string trns []int scale float64 // document scaling factor + dpi float64 } // PointConvert returns the value of pt, expressed in points (1/72 inch), as a @@ -97,17 +98,26 @@ func (f *Fpdf) UnitToPointConvert(u float64) (pt float64) { // Extent returns the width and height of the image in the units of the Fpdf // object. func (info *ImageInfoType) Extent() (wd, ht float64) { - return info.w / info.scale, info.h / info.scale + return info.Width(), info.Height() } // Width returns the width of the image in the units of the Fpdf object. func (info *ImageInfoType) Width() float64 { - return info.w / info.scale + return info.w / (info.scale * info.dpi / 72) } // Height returns the height of the image in the units of the Fpdf object. func (info *ImageInfoType) Height() float64 { - return info.h / info.scale + return info.h / (info.scale * info.dpi / 72) +} + +// Dpi sets the dots per inch for an image +// PNG images MAY have their dpi set automatically, if the image +// specifies it. DPI information is not currently available +// automatically for JPG and GIF images, so if it's important to +// you, you can set it here. It defaults to 72 dpi. +func (info *ImageInfoType) SetDpi(dpi float64) { + info.dpi = dpi } type fontFileType struct { -- cgit v1.2.1-24-ge1ad