jung-kurt / gofpdf

A PDF document generator with high level support for text, drawing and images
http://godoc.org/github.com/jung-kurt/gofpdf
MIT License
4.31k stars 777 forks source link

added imageoptionsreader #281

Closed estenssoros closed 5 years ago

estenssoros commented 5 years ago

I wanted the ability to insert images retrieved as binary (not existing locally). I wasn't sure if you wanted to be able to verify that the image is the correct extension before registering but this will be very useful to me. This is my first attempt contributing to an open-source project. Please be gentle.

jung-kurt commented 5 years ago

This is my first attempt contributing to an open-source project.

Welcome! I hope you make many more contributions. Thanks for including an example that demonstrates your work.

I wanted the ability to insert images retrieved as binary (not existing locally).

Image registration and handling has become seriously convoluted in gofpdf. The idea of placing an image read from an io.Reader and configured with options is a good one, but the problem is that only the options passed with the first call to ImageOptionsReader() would apply for subsequent renderings. (This is due to caching on the part of gofpdf. One could argue that only the image and not particular options should be cached, but that is the way the code was developed.) The fact that configured images that come from a io.Reader is something you needed indicates that better documentation is required, so I reworked your example to show how it can be done with existing methods.

Thanks for the contribution!

estenssoros commented 5 years ago

Thanks!