lib/consolidate/docx/image.rb in standard-procedure-consolidate-0.3.9 vs lib/consolidate/docx/image.rb in standard-procedure-consolidate-0.4.0
- old
+ new
@@ -11,14 +11,22 @@
# Path to use when storing this image within the docx
def storage_path = "word/#{media_path}"
# Convert width from pixels to EMU
- def width = super * EMU_PER_PIXEL
+ def width = super * emu_per_width_pixel
# Convert height from pixels to EMU
- def height = super * EMU_PER_PIXEL
+ def height = super * emu_per_height_pixel
- EMU_PER_PIXEL = (914400 / 72)
+ # Get the width of this image in EMU up to a maximum page width (also in EMU)
+ def clamped_width(maximum = 7_772_400) = [width, maximum].min
+
+ # Get the height of this image in EMU adjusted for a maximum page width (also in EMU)
+ def clamped_height(maximum = 7_772_400) = (height * clamped_width(maximum).to_f / width.to_f).to_i
+
+ def emu_per_width_pixel = 914_400 / dpi[:x]
+
+ def emu_per_height_pixel = 914_400 / dpi[:y]
end
end
end