Class: MapPrint::PngHandler
- Inherits:
-
Object
- Object
- MapPrint::PngHandler
- Defined in:
- lib/map_print/png_handler.rb
Instance Method Summary collapse
-
#initialize(context) ⇒ PngHandler
constructor
A new instance of PngHandler.
- #print ⇒ Object
- #print_map ⇒ Object
Methods included from MapPrint::PngHandlers::Texts
#draw_text, #print_texts, #sanitize_options
Methods included from MapPrint::PngHandlers::Images
Constructor Details
#initialize(context) ⇒ PngHandler
Returns a new instance of PngHandler.
9 10 11 |
# File 'lib/map_print/png_handler.rb', line 9 def initialize(context) @context = context end |
Instance Method Details
#print ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/map_print/png_handler.rb', line 13 def print raise ParameterError.new('Missing png_options width attribute') unless @context. && @context.[:width] raise ParameterError.new('Missing png_options height attribute') unless @context.[:height] `convert -density 300 -size #{@context.png_options[:width]}x#{@context.png_options[:height]} xc:#{@context.png_options[:background_color] || 'transparent'} #{@context.output_path}` @png = MiniMagick::Image.new @context.output_path print_map print_images(@context.images, @png) print_texts(@context.texts, @png) = @context. if (MiniMagick::Image.new(.path), @context.[:position]) end legend_image = @context.print_legend if legend_image (MiniMagick::Image.new(legend_image.path), @context.legend[:position]) end end |
#print_map ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/map_print/png_handler.rb', line 35 def print_map map_image = @context.print_layers size = @context.map[:size] geometry = '' if size && (size[:width] || size[:height]) geometry += size[:width].to_s if size[:width] geometry += 'x' geometry += size[:height].to_s if size[:height] image = MiniMagick::Image.new(map_image.path) image. do |c| c.density 300 c.resize geometry c.unsharp '1.5x1+0.7+0.02' end image.write map_image.path end map_image = @context.print_geojson(MiniMagick::Image.new(map_image.path)) (map_image, @context.map[:position]) end |