summaryrefslogtreecommitdiff
path: root/def.go
diff options
context:
space:
mode:
authorkentquirk <kentquirk@gmail.com>2016-03-07 14:46:05 -0500
committerkentquirk <kentquirk@gmail.com>2016-03-07 14:46:05 -0500
commit784dacec868d6befa2cfd68db03306de24095654 (patch)
treef53bd4f71815596c7e1015ea99240da94079494d /def.go
parentb799c70389290d191c0ec9fba5a2e2b15df96574 (diff)
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.
Diffstat (limited to 'def.go')
-rw-r--r--def.go16
1 files changed, 13 insertions, 3 deletions
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 {