Module: MapPrint::PdfHandlers::Images

Included in:
MapPrint::PdfHandler
Defined in:
lib/map_print/pdf_handlers/images.rb

Instance Method Summary collapse

Instance Method Details

#image_options(image, bounds_top) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/map_print/pdf_handlers/images.rb', line 16

def image_options(image, bounds_top)
  position = {}

  if image[:position]
    position[:at] = image[:position].values
    position[:at][1] = bounds_top - position[:at][1]
  end

  if image[:options][:fit]
    position[:fit] = [image[:options][:fit][:width], image[:options][:fit][:height]]
  end

  image[:options].merge position
end


4
5
6
7
8
9
10
11
12
13
14
# File 'lib/map_print/pdf_handlers/images.rb', line 4

def print_images(images, pdf)
  (images || []).each do |image|
    if image[:path] =~ /https?:\/\//
      image_file = open(image[:path])
    else
      image_file = image[:path]
    end

    pdf.image image_file, image_options(image, pdf.bounds.top)
  end
end