smappy 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -3,6 +3,8 @@ require 'bundler'
3
3
  Bundler.setup
4
4
  Bundler.require
5
5
 
6
+ Bundler::GemHelper.install_tasks
7
+
6
8
  $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
7
9
  require 'smappy'
8
10
 
@@ -22,15 +24,13 @@ namespace :smappy do
22
24
  # Google Maps tiles:
23
25
  # map.tile_url_template = 'http://mt1.google.com/vt/x=%{x}&y=%{y}&z=%{zoomlevel}'
24
26
 
25
- canvas = map.to_image
26
- drawing = Magick::Draw.new
27
+ image = map.to_image
27
28
 
28
29
  marker = Smappy::Marker.new(map.center.latitude, map.center.longitude)
29
30
  position = marker.position_on_map(map)
30
-
31
- drawing.composite(position[0], position[1], marker.width, marker.height, marker.marker_image)
32
- drawing.draw(canvas)
33
-
34
- canvas.write 'tmp/map.png'
31
+
32
+ image.compose!(marker.marker_image, position[0], position[1])
33
+
34
+ image.save 'tmp/map.png'
35
35
  end
36
36
  end
data/lib/smappy.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Smappy
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
 
4
4
  autoload :Location, 'smappy/location'
5
5
  autoload :Marker, 'smappy/marker'
data/lib/smappy/marker.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'open-uri'
2
- require 'rmagick'
2
+ require 'chunky_png'
3
3
 
4
4
  module Smappy
5
5
  class Marker < Location
@@ -15,11 +15,11 @@ module Smappy
15
15
  end
16
16
 
17
17
  def width
18
- marker_image.columns
18
+ marker_image.width
19
19
  end
20
20
 
21
21
  def height
22
- marker_image.rows
22
+ marker_image.height
23
23
  end
24
24
 
25
25
  def position_on_map(map)
@@ -30,9 +30,8 @@ module Smappy
30
30
 
31
31
  # UNTESTED:
32
32
  def marker_image
33
- @marker_image ||= (
34
- data = open(image).read
35
- Magick::Image.from_blob(data).first
33
+ @marker_image ||= ChunkyPNG::Image.from_datastream(
34
+ ChunkyPNG::Datastream.from_io(open(image))
36
35
  )
37
36
  end
38
37
  end
@@ -1,4 +1,4 @@
1
- require 'rmagick'
1
+ require 'chunky_png'
2
2
 
3
3
  module Smappy
4
4
  class StaticMap
@@ -67,16 +67,30 @@ module Smappy
67
67
  end
68
68
 
69
69
  def to_image
70
- canvas = Magick::Image.new(width, height)
71
- drawing = Magick::Draw.new
70
+ canvas = ChunkyPNG::Image.new(width, height)
72
71
 
73
72
  tiles.each do |tile|
74
- position = tile.position_on_map(self)
75
- drawing.composite(position[0], position[1], Tile::SIZE, Tile::SIZE, tile.to_image)
73
+ x, y = tile.position_on_map(self)
74
+ image = tile.to_image
75
+
76
+ if x < 0 || y < 0
77
+ crop_x = x < 0 ? -x : 0
78
+ crop_y = y < 0 ? -y : 0
79
+ x, y = [0, x].max, [0, y].max
80
+
81
+ image.crop!(crop_x, crop_y, image.width - crop_x, image.height - crop_y)
82
+ end
83
+
84
+ if x + image.width > canvas.width || y + image.height > height
85
+ crop_width = [image.width, canvas.width - x].min
86
+ crop_height = [image.height, canvas.height - y].min
87
+
88
+ image.crop!(0, 0, crop_width, crop_height)
89
+ end
90
+
91
+ canvas.compose!(image, x, y)
76
92
  end
77
93
 
78
- drawing.draw(canvas)
79
-
80
94
  canvas
81
95
  end
82
96
  end
data/lib/smappy/tile.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'open-uri'
2
- require 'rmagick'
2
+ require 'chunky_png'
3
3
 
4
4
  module Smappy
5
5
  class Tile
@@ -33,8 +33,9 @@ module Smappy
33
33
  end
34
34
 
35
35
  def to_image
36
- data = open(to_url).read
37
- Magick::Image.from_blob(data).first
36
+ @tile_image ||= ChunkyPNG::Image.from_datastream(
37
+ ChunkyPNG::Datastream.from_io(open(to_url))
38
+ )
38
39
  end
39
40
 
40
41
  def x
@@ -121,7 +121,7 @@ describe Smappy::StaticMap do
121
121
 
122
122
  it 'returns an image of the specified size' do
123
123
  img = map.to_image
124
- [img.columns, img.rows].should == [500, 350]
124
+ [img.width, img.height].should == [500, 350]
125
125
  end
126
126
  end
127
127
  end
@@ -81,7 +81,7 @@ describe Smappy::Tile do
81
81
 
82
82
  it 'returns the image at the url' do
83
83
  img = tile.to_image
84
- [img.columns, img.rows].should == [256, 256]
84
+ [img.width, img.height].should == [256, 256]
85
85
  end
86
86
  end
87
87
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smappy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,8 +12,8 @@ cert_chain: []
12
12
  date: 2011-12-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rmagick
16
- requirement: &70193770877180 !ruby/object:Gem::Requirement
15
+ name: chunky_png
16
+ requirement: &70314486828360 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70193770877180
24
+ version_requirements: *70314486828360
25
25
  description: Generate static maps of map tiles.
26
26
  email: tomeric@eet.nu
27
27
  executables: []
@@ -57,12 +57,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
57
  - - ! '>='
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0'
60
+ segments:
61
+ - 0
62
+ hash: 1242191568019221092
60
63
  required_rubygems_version: !ruby/object:Gem::Requirement
61
64
  none: false
62
65
  requirements:
63
66
  - - ! '>='
64
67
  - !ruby/object:Gem::Version
65
68
  version: '0'
69
+ segments:
70
+ - 0
71
+ hash: 1242191568019221092
66
72
  requirements: []
67
73
  rubyforge_project:
68
74
  rubygems_version: 1.8.10