tileup 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/tileup.rb +14 -15
  2. metadata +1 -1
@@ -1,5 +1,6 @@
1
1
  require 'ostruct'
2
- require 'rmagick'
2
+ require 'RMagick'
3
+ require 'fileutils'
3
4
 
4
5
  module TileUp
5
6
 
@@ -15,11 +16,13 @@ module TileUp
15
16
  verbose: false
16
17
  }
17
18
  @options = OpenStruct.new(default_options.merge(options))
19
+ @options.tile_width = @options.tile_width.to_i unless !@options.tile_width.respond_to? :to_i
20
+ @options.tile_height = @options.tile_height.to_i unless !@options.tile_height.respond_to? :to_i
18
21
  @extension = image_filename.split(".").last
19
22
  @filename_prefix = @options.filename_prefix
20
23
 
21
24
  begin
22
- @image = Magick::Image::read(image_filename).first
25
+ @image = Magick::Image::read(image_filename).first
23
26
  rescue Magick::ImageMagickError => e
24
27
  puts "Could not open image #{image_filename}."
25
28
  exit
@@ -61,17 +64,17 @@ module TileUp
61
64
  output_dir: File.join(@options.output_dir, zoom_name.to_s),
62
65
  scale: scale
63
66
  }
64
- end
67
+ end
65
68
  end
66
69
 
67
70
  # run through tasks list
68
71
  tasks.each do |task|
69
72
  image = @image
70
73
  image_path = File.join(task[:output_dir], @filename_prefix)
71
- if task[:scale] != 1.0
74
+ if task[:scale] != 1.0
72
75
  # if scale required, scale image
73
76
  begin
74
- image = @image.scale(task[:scale])
77
+ image = @image.scale(task[:scale])
75
78
  rescue RuntimeError => e
76
79
  message = "Failed to scale image, are you sure the original image "\
77
80
  "is large enough to scale down this far (#{scale}) with this "\
@@ -91,19 +94,15 @@ module TileUp
91
94
  end
92
95
 
93
96
  def make_path(directory_path)
94
- parts = directory_path.split(File::SEPARATOR);
95
- parts.each_index do |i|
96
- upto = parts[0..i].join(File::SEPARATOR)
97
- Dir::mkdir(upto) unless Dir::exists?(upto)
98
- end
97
+ FileUtils.mkdir_p directory_path
99
98
  end
100
99
 
101
100
  def make_tiles(image, filename_prefix, tile_width, tile_height)
102
101
  # find image width and height
103
- # then find out how many tiles we'll get out of
102
+ # then find out how many tiles we'll get out of
104
103
  # the image, then use that for the xy offset in crop.
105
- num_columns = image.columns/tile_width
106
- num_rows = image.rows/tile_height
104
+ num_columns = (image.columns/tile_width.to_f).ceil
105
+ num_rows = (image.rows/tile_height.to_f).ceil
107
106
  x,y,column,row = 0,0,0,0
108
107
  crops = []
109
108
 
@@ -136,7 +135,7 @@ module TileUp
136
135
  ci = nil
137
136
  end
138
137
  end
139
-
138
+
140
139
  end
141
140
 
142
- end
141
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tileup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: