mugshot 0.1.0 → 0.1.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -12,10 +12,13 @@ class Mugshot::Application < Sinatra::Base
12
12
  end
13
13
 
14
14
  get '/:size/:id.:ext' do |size, id, ext|
15
- size = size.split("x")
16
15
  image = @storage.read(id)
17
16
  halt 404 if image.nil?
18
- image.resize! size[0].to_i, size[1].to_i
17
+
18
+ dimm = Mugshot::Dimension.parse!(size)
19
+
20
+ image.resize_to_fit! *dimm.size if dimm.will_keep_aspect?
21
+ image.resize! *dimm.size unless dimm.will_keep_aspect?
19
22
  image.to_blob
20
23
  end
21
24
 
@@ -25,6 +28,11 @@ class Mugshot::Application < Sinatra::Base
25
28
  image.to_blob
26
29
  end
27
30
 
31
+ get '/_status' do
32
+ content_type :html
33
+ "OK"
34
+ end
35
+
28
36
  protected
29
37
 
30
38
  def initialize(storage)
@@ -0,0 +1,25 @@
1
+ class Mugshot::Dimension
2
+ attr_reader :width, :height
3
+
4
+ def self.parse!(str)
5
+ data = /(\d*)x(\d*)/.match(str)
6
+ new(data[1].to_i,data[2].to_i)
7
+ end
8
+
9
+ def to_s
10
+ "#{@width}x#{@height}"
11
+ end
12
+
13
+ def size
14
+ return @width, @height
15
+ end
16
+
17
+ def will_keep_aspect?
18
+ (@width == 0) || (@height == 0)
19
+ end
20
+
21
+ def initialize (width, height)
22
+ @width = width
23
+ @height = height
24
+ end
25
+ end
data/lib/mugshot/image.rb CHANGED
@@ -1,14 +1,18 @@
1
1
  class Mugshot::Image
2
- def resize!(width, height)
2
+ def resize!(width, height = nil)
3
+ height ||= width
3
4
  @image.resize! width, height
4
5
  end
6
+
7
+ def resize_to_fit!(width, height = nil)
8
+ @image.resize_to_fit!(width)
9
+ end
5
10
 
6
11
  def to_blob
7
12
  @image.to_blob
8
13
  end
9
14
 
10
15
  protected
11
-
12
16
  def initialize(file)
13
17
  @image = Magick::Image.read(file).first
14
18
  end
data/lib/mugshot.rb CHANGED
@@ -12,7 +12,9 @@ require 'RMagick'
12
12
  module Mugshot
13
13
  end
14
14
 
15
+ require 'mugshot/dimension'
15
16
  require 'mugshot/image'
16
17
  require 'mugshot/storage'
17
18
  require 'mugshot/fs_storage'
18
19
  require 'mugshot/application'
20
+
data/mugshot.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mugshot}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Cain\303\243 Nunes", "Fabr\303\255cio Lopes", "Fernando Meyer", "Guilherme Cirne", "Jos\303\251 Peleteiro"]
@@ -35,11 +35,14 @@ Gem::Specification.new do |s|
35
35
  "gems_dev.yml",
36
36
  "lib/mugshot.rb",
37
37
  "lib/mugshot/application.rb",
38
+ "lib/mugshot/dimension.rb",
38
39
  "lib/mugshot/fs_storage.rb",
39
40
  "lib/mugshot/image.rb",
40
41
  "lib/mugshot/storage.rb",
42
+ "mugshot.gemspec",
41
43
  "spec/files/test.jpg",
42
44
  "spec/mugshot/application_spec.rb",
45
+ "spec/mugshot/dimension_spec.rb",
43
46
  "spec/mugshot/fs_storage_spec.rb",
44
47
  "spec/mugshot/image_spec.rb",
45
48
  "spec/spec.opts",
@@ -53,6 +56,7 @@ Gem::Specification.new do |s|
53
56
  s.summary = %q{Image server}
54
57
  s.test_files = [
55
58
  "spec/mugshot/application_spec.rb",
59
+ "spec/mugshot/dimension_spec.rb",
56
60
  "spec/mugshot/fs_storage_spec.rb",
57
61
  "spec/mugshot/image_spec.rb",
58
62
  "spec/spec_helper.rb"
@@ -8,6 +8,12 @@ describe Mugshot::Application do
8
8
  end
9
9
  end
10
10
 
11
+ describe 'GET /_status' do
12
+ get '/_status'
13
+ last_response.status.should == 200
14
+ last_response.body.should == 'OK'
15
+ end
16
+
11
17
  describe 'POST /' do
12
18
  it "should create image" do
13
19
  file_read = nil
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Mugshot::Dimension do
4
+ it "should parse a double size value" do
5
+ Mugshot::Dimension.parse!("100x100").size.should == [100,100]
6
+ end
7
+
8
+ it "should parse a single left value" do
9
+ Mugshot::Dimension.parse!("100x").size.should == [100, 0]
10
+ end
11
+
12
+ it "should parse a single right value" do
13
+ Mugshot::Dimension.parse!("x100").size.should == [0, 100]
14
+ end
15
+
16
+ it "should keep aspect" do
17
+ Mugshot::Dimension.parse!("x100").will_keep_aspect?.should == true
18
+ Mugshot::Dimension.parse!("100x").will_keep_aspect?.should == true
19
+ end
20
+
21
+ it "should parse and convert" do
22
+ Mugshot::Dimension.parse!("100x100").to_s.should == "100x100"
23
+ end
24
+ end
25
+
@@ -11,7 +11,6 @@ describe Mugshot::Image do
11
11
  it 'should return image as a blob' do
12
12
  blob_data = 'blob data'
13
13
  @magick_image.stub!(:to_blob).and_return(blob_data)
14
-
15
14
  @image.to_blob.should == blob_data
16
15
  end
17
16
 
@@ -19,7 +18,18 @@ describe Mugshot::Image do
19
18
  width = 300
20
19
  height = 200
21
20
  @magick_image.should_receive(:resize!).with(width, height)
22
-
23
21
  @image.resize! width, height
24
22
  end
23
+
24
+ it "should resize image with dimension" do
25
+ @magick_image.should_receive(:resize!).with(300, 200)
26
+ dim = Mugshot::Dimension.parse!("300x200")
27
+ @image.resize! *dim.size
28
+ end
29
+
30
+ it "should resize image fixed dimension" do
31
+ @magick_image.should_receive(:resize_to_fit!).with(300)
32
+ dim = Mugshot::Dimension.parse!("300x")
33
+ @image.resize_to_fit! *dim.size
34
+ end
25
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mugshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Cain\xC3\xA3 Nunes"
@@ -139,12 +139,14 @@ files:
139
139
  - gems_dev.yml
140
140
  - lib/mugshot.rb
141
141
  - lib/mugshot/application.rb
142
+ - lib/mugshot/dimension.rb
142
143
  - lib/mugshot/fs_storage.rb
143
144
  - lib/mugshot/image.rb
144
145
  - lib/mugshot/storage.rb
145
146
  - mugshot.gemspec
146
147
  - spec/files/test.jpg
147
148
  - spec/mugshot/application_spec.rb
149
+ - spec/mugshot/dimension_spec.rb
148
150
  - spec/mugshot/fs_storage_spec.rb
149
151
  - spec/mugshot/image_spec.rb
150
152
  - spec/spec.opts
@@ -180,6 +182,7 @@ specification_version: 3
180
182
  summary: Image server
181
183
  test_files:
182
184
  - spec/mugshot/application_spec.rb
185
+ - spec/mugshot/dimension_spec.rb
183
186
  - spec/mugshot/fs_storage_spec.rb
184
187
  - spec/mugshot/image_spec.rb
185
188
  - spec/spec_helper.rb