summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdf.go67
-rw-r--r--fpdf_test.go40
2 files changed, 20 insertions, 87 deletions
diff --git a/fpdf.go b/fpdf.go
index 319e89d..ca48fb5 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -2986,73 +2986,6 @@ func (f *Fpdf) ImageOptions(imageNameStr string, x, y, w, h float64, flow bool,
return
}
-// ImageOptionsReader registers an image, reading it from Reader r, and puts a
-// JPEG, PNG or GIF image in the current page. The size it will take on the
-// page can be specified in different ways. If both w and h are 0, the image
-// is rendered at 96 dpi. If either w or h is zero, it will be calculated from
-// the other dimension so that the aspect ratio is maintained. If w and/or h are -1,
-// the dpi for that dimension will be read from the ImageInfoType object. PNG
-// files can contain dpi information, and if present, this information will be
-// populated in the ImageInfoType object and used in Width, Height, and Extent
-// calculations. Otherwise, the SetDpi function can be used to change the dpi
-// from the default of 72.
-//
-// If w and h are any other negative value, their absolute values
-// indicate their dpi extents.
-//
-// Supported JPEG formats are 24 bit, 32 bit and gray scale. Supported PNG
-// formats are 24 bit, indexed color, and 8 bit indexed gray scale. If a GIF
-// image is animated, only the first frame is rendered. Transparency is
-// supported. It is possible to put a link on the image.
-//
-// imageNameStr may be the name of an image as registered with a call to either
-// RegisterImageReader() or RegisterImage(). In the first case, the image is
-// loaded using an io.Reader. This is generally useful when the image is
-// obtained from some other means than as a disk-based file. In the second
-// case, the image is loaded as a file. Alternatively, imageNameStr may
-// directly specify a sufficiently qualified filename.
-//
-// r is an io.Reader that implements the Read() function
-//
-// However the image is loaded, if it is used more than once only one copy is
-// embedded in the file.
-//
-// If x is negative, the current abscissa is used.
-//
-// If flow is true, the current y value is advanced after placing the image and
-// a page break may be made if necessary.
-//
-// If link refers to an internal page anchor (that is, it is non-zero; see
-// AddLink()), the image will be a clickable internal link. Otherwise, if
-// linkStr specifies a URL, the image will be a clickable external link.
-func (f *Fpdf) ImageOptionsReader(imageNameStr string, r io.Reader, x, y, w, h float64, flow bool, options ImageOptions, link int, linkStr string) {
- if f.err != nil {
- return
- }
-
- var info *ImageInfoType
-
- i, ok := f.images[imageNameStr]
- if ok {
- info = i
- } else {
- if options.ImageType == "" {
- pos := strings.LastIndex(imageNameStr, ".")
- if pos < 0 {
- f.err = fmt.Errorf("image file has no extension and no type was specified: %s", imageNameStr)
- return
- }
- options.ImageType = imageNameStr[pos+1:]
- }
- info = f.RegisterImageOptionsReader(imageNameStr, options, r)
- if f.err != nil {
- return
- }
- }
- f.imageOut(info, x, y, w, h, options.AllowNegativePosition, flow, link, linkStr)
- return
-}
-
// RegisterImageReader registers an image, reading it from Reader r, adding it
// to the PDF file but not adding it to the page.
//
diff --git a/fpdf_test.go b/fpdf_test.go
index 54de6c2..63c28c5 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -858,37 +858,37 @@ func ExampleFpdf_ImageOptions() {
// Successfully generated pdf/Fpdf_ImageOptions.pdf
}
-// ImageOption struct can be used to affect horizontal image placement.
-func ExampleFpdf_ImageOptionsReader() {
- var opt gofpdf.ImageOptions
- var pdfStr, imgStr string
- var fl *os.File
- var err error
+// ExampleFpdf_RegisterImageOptionsReader demonstrates how to load an image
+// from a io.Reader (in this case, a file) and register it with options.
+func ExampleFpdf_RegisterImageOptionsReader() {
+ var (
+ opt gofpdf.ImageOptions
+ pdfStr string
+ fl *os.File
+ err error
+ )
- pdfStr = example.Filename("Fpdf_ImageOptionsReader")
+ pdfStr = example.Filename("Fpdf_RegisterImageOptionsReader")
pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.SetFont("Arial", "", 11)
- pdf.SetX(60)
- opt.ImageType = "png"
- imgStr = example.ImageFile("logo.png")
- fl, err = os.Open(imgStr)
+ fl, err = os.Open(example.ImageFile("logo.png"))
if err == nil {
- pdf.ImageOptionsReader(imgStr, fl, -10, 10, 30, 0, false, opt, 0, "")
+ opt.ImageType = "png"
opt.AllowNegativePosition = true
- _, err = fl.Seek(0, 0)
- if err == nil {
- pdf.ImageOptionsReader(imgStr, fl, -10, 50, 30, 0, false, opt, 0, "")
- err = pdf.OutputFileAndClose(pdfStr)
- }
+ _ = pdf.RegisterImageOptionsReader("logo", opt, fl)
fl.Close()
+ for x := -20.0; x <= 40.0; x += 5 {
+ pdf.ImageOptions("logo", x, x+30, 0, 0, false, opt, 0, "")
+ }
+ err = pdf.OutputFileAndClose(pdfStr)
}
example.Summary(err, pdfStr)
// Output:
- // Successfully generated pdf/Fpdf_ImageOptionsReader.pdf
+ // Successfully generated pdf/Fpdf_RegisterImageOptionsReader.pdf
}
-// This examples demonstrates Landscape mode with images.
+// This example demonstrates Landscape mode with images.
func ExampleFpdf_SetAcceptPageBreakFunc() {
var y0 float64
var crrntCol int
@@ -948,7 +948,7 @@ func ExampleFpdf_SetAcceptPageBreakFunc() {
// Successfully generated pdf/Fpdf_SetAcceptPageBreakFunc_landscape.pdf
}
-// This examples tests corner cases as reported by the gocov tool.
+// This example tests corner cases as reported by the gocov tool.
func ExampleFpdf_SetKeywords() {
var err error
fileStr := example.Filename("Fpdf_SetKeywords")