Module: Thinreports::BasicReport::Generator::PrawnExt::CalcImageDimensions
- Defined in:
- lib/thinreports/basic_report/generator/pdf/prawn_ext/calc_image_dimensions.rb
Instance Method Summary collapse
-
#calc_image_dimensions(options) ⇒ Object
Implement :auto_fit option for image size calculation.
Instance Method Details
#calc_image_dimensions(options) ⇒ Object
Implement :auto_fit option for image size calculation.
When the image is larger than the box, the original: fit option does not change the image size. The :auto_fit option changes the image size to fit in the box while maintaining the aspect ratio.
Usage:
image '/path/to/image.png', at: [100, 100], auto_fit: [100, 100]
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/thinreports/basic_report/generator/pdf/prawn_ext/calc_image_dimensions.rb', line 17 def calc_image_dimensions() if [:auto_fit] image_width = [:width] || width image_height = [:height] || height box_width, box_height = .delete(:auto_fit) [:fit] = [box_width, box_height] if image_width > box_width || image_height > box_height end super() end |