mapel 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/Rakefile +1 -1
  2. data/lib/mapel.rb +16 -35
  3. data/mapel.gemspec +2 -2
  4. data/spec/mapel_spec.rb +6 -2
  5. metadata +2 -2
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
 
4
4
  name = 'mapel'
5
- version = '0.1.5'
5
+ version = '0.1.6'
6
6
 
7
7
  begin
8
8
  require 'jeweler'
@@ -74,26 +74,8 @@ module Mapel
74
74
  end
75
75
 
76
76
  def resize!(*args)
77
- @commands << lambda {
78
- cmd = self.class.new
79
- width, height = Geometry.new(*args).dimensions
80
- if @source
81
- origin_width, origin_height = Mapel.info(@source)[:dimensions]
82
-
83
- # Crop dimensions should not exceed original dimensions.
84
- width = [width, origin_width].min
85
- height = [height, origin_height].min
86
-
87
- if width != origin_width || height != origin_height
88
- scale = [width/origin_width.to_f, height/origin_height.to_f].max
89
- cmd.resize((scale*(origin_width+0.5)), (scale*(origin_height+0.5)))
90
- end
91
- cmd.crop(width, height).to_preview
92
- else
93
- "\{crop_resized #{args}\}"
94
- end
95
- }
96
- self
77
+ width, height = Geometry.new(*args).dimensions
78
+ resize("#{width}x#{height}^").crop(width, height).repage
97
79
  end
98
80
 
99
81
  def scale(*args)
@@ -122,9 +104,14 @@ module Mapel
122
104
  end
123
105
 
124
106
  def to_info_hash
125
- meta = {}
126
- meta[:dimensions] = @output.split(' ')[2].split('x').map { |d| d.to_i }
127
- meta
107
+ meta = @output.split(' ')
108
+ {
109
+ :path => meta[0],
110
+ :format => meta[1],
111
+ :dimensions => meta[2].split('x').map {|d| d.to_i},
112
+ :depth => meta[4],
113
+ :size => meta[6]
114
+ }
128
115
  end
129
116
  end
130
117
  end
@@ -132,23 +119,15 @@ module Mapel
132
119
  class Geometry
133
120
  attr_accessor :width, :height, :x, :y, :flag
134
121
 
135
- FLAGS = ['', '%', '<', '>', '!', '@']
136
- RFLAGS = {
137
- '%' => :percent,
138
- '!' => :aspect,
139
- '<' => :<,
140
- '>' => :>,
141
- '@' => :area
142
- }
122
+ FLAGS = ['', '%', '<', '>', '!', '@', '^']
143
123
 
144
124
  # Regex parser for geometry strings
145
- RE = /\A(\d*)(?:x(\d+)?)?([-+]\d+)?([-+]\d+)?([%!<>@]?)\Z/
125
+ RE = /\A(\d*)(?:x(\d+)?)?([-+]\d+)?([-+]\d+)?([%!<>@\^]?)\Z/
146
126
 
147
127
  def initialize(*args)
148
128
  if (args.length == 1) && (args.first.kind_of?(String))
149
129
  raise(ArgumentError, "Invalid geometry string") unless m = RE.match(args.first)
150
130
  args = m.to_a[1..5]
151
- args[4] = args[4] ? RFLAGS[args[4]] : nil
152
131
  end
153
132
  @width = args[0] ? args[0].to_i.round : 0
154
133
  @height = args[1] ? args[1].to_i.round : 0
@@ -156,7 +135,8 @@ module Mapel
156
135
  raise(ArgumentError, "Height must be >= 0") if @height < 0
157
136
  @x = args[2] ? args[2].to_i : 0
158
137
  @y = args[3] ? args[3].to_i : 0
159
- @flag = (args[4] && RFLAGS.has_value?(args[4])) ? args[4] : nil
138
+ raise(ArgumentError, "Flags must be in: #{FLAGS.inspect}") if args[4] && !FLAGS.include?(args[4])
139
+ @flag = args[4]
160
140
  end
161
141
 
162
142
  def dimensions
@@ -170,7 +150,8 @@ module Mapel
170
150
  str << 'x' if @height > 0
171
151
  str << "%g" % @height if @height > 0
172
152
  str << "%+d%+d" % [@x, @y] if (@x != 0 || @y != 0 || crop)
173
- str << (RFLAGS.respond_to?(:key) ? RFLAGS.key(@flag) : RFLAGS.index(@flag)).to_s
153
+ str << @flag if @flag
154
+ str
174
155
  end
175
156
  end
176
157
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mapel}
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aleksander Williams"]
12
- s.date = %q{2010-02-24}
12
+ s.date = %q{2010-02-25}
13
13
  s.email = %q{alekswilliams@earthlink.net}
14
14
  s.extra_rdoc_files = [
15
15
  "README.rdoc"
@@ -24,8 +24,12 @@ describe Mapel do
24
24
  end
25
25
 
26
26
  describe "#info" do
27
- it "should return image dimensions" do
27
+ it "should return basic image metadata" do
28
+ Mapel.info(@logo)[:path].should == @logo
29
+ Mapel.info(@logo)[:format].should == 'JPEG'
28
30
  Mapel.info(@logo)[:dimensions].should == [572, 591]
31
+ Mapel.info(@logo)[:depth].should == '8-bit'
32
+ Mapel.info(@logo)[:size].should == '95.1kb'
29
33
  end
30
34
  end
31
35
 
@@ -51,7 +55,7 @@ describe Mapel do
51
55
  it "should be able to crop-resize an image" do
52
56
  cmd = Mapel(@logo).gravity(:west).resize!('50x100').to(@output + '/crop_resized.jpg').run
53
57
  cmd.status.should == true
54
- Mapel.info(@output + '/crop_resized.jpg')[:dimensions].should == [50, 99]
58
+ Mapel.info(@output + '/crop_resized.jpg')[:dimensions].should == [50, 100]
55
59
  end
56
60
 
57
61
  it "should allow arbitrary addition of commands to the queue" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mapel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksander Williams
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-24 00:00:00 -05:00
12
+ date: 2010-02-25 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency