mugshot 0.1.5 → 0.2.0

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Fernando Meyer
1
+ Copyright (c) 2009 Jose Peleteiro
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ Mugshot
2
+ =======
3
+
4
+ **Mugshot is a dead simple image server**.
5
+
6
+
7
+ Overview
8
+ --------
9
+
10
+ The basic idea of Mugshot is that you upload the largest/highest quality images
11
+ possible. When retrieving the images you apply different operations to it such
12
+ as: resizing, rounded corners, transparency and anything else we can think of!
13
+
14
+ Only the original image is stored on the server. All operations are performed
15
+ dynamically, which is why caching is so important (see below).
16
+
17
+
18
+ Caching
19
+ -------
20
+
21
+ Mugshot doesn't cache anything by itself but is designed to play nice with
22
+ standard HTTP caching.
23
+
24
+ For production use, don't even think about using Mugshot without something like
25
+ Varnish or Squid sitting in front.
26
+
27
+
28
+ Supported Operations
29
+ --------------------
30
+
31
+ ### Resize
32
+
33
+ /widthxheight/id.jpg (ex: http://mugshot.ws/200x100/test.jpg)
34
+
35
+ ### Resize keeping aspect ratio
36
+
37
+ /widthx/id.jpg (ex.: http://mugshot.ws/200x/test.jpg)
38
+
39
+ /xheight/id.jpg (ex.: http://mugshot.ws/x100/test.jpg)
40
+
41
+
42
+ Who's using
43
+ -----------
44
+
45
+ We currently use Mugshot with Varnish on [Baixatudo](http://www.baixatudo.com.br).
@@ -3,10 +3,8 @@ Feature: Retrieve resized image
3
3
  Scenario: Successful retrieval of resized image
4
4
  When I upload an image
5
5
  And I ask for the 200x200 resized image
6
-
7
6
  Then I should get the 200x200 resized image
8
7
 
9
8
  Scenario: Image doesn't exist
10
9
  When I ask for a 200x200 resized image that doesn't exist
11
-
12
10
  Then I should get a 404 response
@@ -15,3 +15,11 @@ end
15
15
  Then /^I should get a (\d+) response$/ do |response_code|
16
16
  last_response.status.should == response_code.to_i
17
17
  end
18
+
19
+ Then /^I should get the (.*) resized image$/ do |size|
20
+ @retrieved_image.should be_same_image_as("test.#{size}.jpg")
21
+ end
22
+
23
+ Then /^I should get the (.*) resized image keeping the aspect ratio$/ do |size|
24
+ @retrieved_image.should be_same_image_as("test.#{size}.jpg")
25
+ end
@@ -1,10 +1,3 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
-
3
- gems = YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'gems_dev.yml'))
4
- gems.each do |depgem|
5
- gem "#{depgem[:name]}", "#{depgem[:version]}"
6
- end
7
-
8
1
  require 'mugshot'
9
2
 
10
3
  require 'rack/test'
@@ -25,3 +18,11 @@ After do
25
18
  require 'fileutils'
26
19
  FileUtils.rm_rf("/tmp/mugshot/cucumber")
27
20
  end
21
+
22
+ Spec::Matchers.define :be_same_image_as do |expected_filename|
23
+ match do |actual_blob|
24
+ actual = Magick::Image.from_blob(actual_blob).first
25
+ expected = Magick::Image.read("features/support/files/#{expected_filename}").first
26
+ actual.get_pixels(0, 0, actual.columns, actual.rows) == expected.get_pixels(0, 0, expected.columns, expected.rows)
27
+ end
28
+ end
@@ -1,15 +1,16 @@
1
1
  require 'sinatra/base'
2
-
3
2
  class Mugshot::Application < Sinatra::Base
4
3
 
5
4
  set :static, true
6
5
  set :public, ::File.expand_path(::File.join(::File.dirname(__FILE__), "public"))
7
6
 
8
- before do
7
+ before do
8
+ response['Cache-Control'] = "public, max-age=#{1.year.to_i}"
9
9
  content_type :jpg
10
10
  end
11
11
 
12
12
  get '/?' do
13
+ content_type :html
13
14
  'ok'
14
15
  end
15
16
 
@@ -18,24 +19,30 @@ class Mugshot::Application < Sinatra::Base
18
19
  @storage.write(params['file'][:tempfile].read)
19
20
  end
20
21
 
21
- get '/:size/:id.:ext' do |size, id, ext|
22
+ get '/:size/:id.:format' do |size, id, format|
22
23
  image = @storage.read(id)
23
-
24
- halt 404 if image.nil?
25
-
26
- dimm = Mugshot::Dimension.parse!(size)
27
- image.resize! dimm
28
- image.to_blob
29
- end
24
+ halt 404 if image.blank?
30
25
 
31
- get '/:id.:ext' do |id, ext|
32
- image = @storage.read(id)
33
- halt 404 if image.nil?
34
- image.to_blob
26
+ begin
27
+ resize(image, size)
28
+ send_image(image, format.to_sym)
29
+ ensure
30
+ image.destroy!
31
+ end
35
32
  end
36
33
 
37
34
  protected
38
35
  def initialize(storage)
39
36
  @storage = storage
40
37
  end
38
+
39
+ def resize(image, size)
40
+ image.resize!(size)
41
+ end
42
+
43
+ def send_image(image, format)
44
+ content_type format
45
+ response['Content-Disposition'] = 'inline'
46
+ image.to_blob(:format => format)
47
+ end
41
48
  end
data/lib/mugshot/image.rb CHANGED
@@ -1,16 +1,43 @@
1
+
1
2
  class Mugshot::Image
2
- def resize!(dimension)
3
- return @image.resize_to_fit! *dimension.size if dimension.will_keep_aspect?
4
- @image.resize! dimension.width, dimension.height
3
+
4
+ def width
5
+ @image.columns
6
+ end
7
+
8
+ def height
9
+ @image.rows
10
+ end
11
+
12
+ def resize!(size)
13
+ w, h = size.to_s.split("x").map{|i| i.blank? ? nil : i.to_i}
14
+
15
+ if [w, h].include?(nil)
16
+ @image.resize_to_fit! w, h
17
+ else
18
+ @image.resize! w, h
19
+ end
20
+
21
+ self
22
+ end
23
+
24
+ def destroy!
25
+ @image.destroy!
26
+ self
5
27
  end
6
28
 
7
- def to_blob
8
- @image.to_blob
29
+ def to_blob(opts = {})
30
+ @image.strip!
31
+ @image.to_blob do
32
+ self.format = opts[:format].to_s if opts[:format].present?
33
+ self.quality = opts[:quality] if opts[:quality].present?
34
+ end
9
35
  end
10
36
 
11
37
  protected
12
-
38
+
13
39
  def initialize(file)
14
40
  @image = Magick::Image.read(file).first
15
41
  end
42
+
16
43
  end
data/lib/mugshot.rb CHANGED
@@ -1,8 +1,3 @@
1
- gems = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'gems.yml'))
2
- gems.each do |depgem|
3
- gem "#{depgem[:name]}", "#{depgem[:version]}"
4
- end
5
-
6
1
  require 'rubygems'
7
2
  require 'fileutils'
8
3
  require 'uuid'
@@ -12,8 +7,7 @@ require 'RMagick'
12
7
  module Mugshot
13
8
  end
14
9
 
15
- require 'mugshot/dimension'
16
- require 'mugshot/image'
10
+ require 'mugshot/image'
17
11
  require 'mugshot/storage'
18
12
  require 'mugshot/fs_storage'
19
13
  require 'mugshot/application'
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe Mugshot::Application do
4
4
  before :each do
@@ -8,13 +8,13 @@ describe Mugshot::Application do
8
8
  end
9
9
  end
10
10
 
11
- describe 'POST /' do
11
+ describe "POST /" do
12
12
  it "should create image" do
13
13
  file_read = nil
14
14
  File.open("spec/files/test.jpg") {|f| file_read = f.read}
15
15
  @storage.should_receive(:write).with(file_read)
16
16
 
17
- post '/', "file" => Rack::Test::UploadedFile.new("spec/files/test.jpg", "image/jpeg")
17
+ post "/", "file" => Rack::Test::UploadedFile.new("spec/files/test.jpg", "image/jpeg")
18
18
 
19
19
  last_response.status.should == 200
20
20
  end
@@ -22,23 +22,21 @@ describe Mugshot::Application do
22
22
  it "should return image id" do
23
23
  @storage.stub!(:write).and_return("batata")
24
24
 
25
- post '/', "file" => Rack::Test::UploadedFile.new("spec/files/test.jpg", "image/jpeg")
25
+ post "/", "file" => Rack::Test::UploadedFile.new("spec/files/test.jpg", "image/jpeg")
26
26
 
27
27
  last_response.body.should == "batata"
28
28
  end
29
29
  end
30
30
 
31
- describe 'GET /:size/:id.:ext' do
32
- it 'should return resized image' do
33
- dimension = mock(Mugshot::Dimension)
34
- Mugshot::Dimension.stub!(:parse!).with('200x200').and_return(dimension)
35
-
31
+ describe "GET /:size/:id.:ext" do
32
+ it "should return resized image" do
36
33
  image = mock(Mugshot::Image)
37
- image.stub!(:to_blob).and_return('image data')
38
- image.should_receive(:resize!).with(dimension)
39
- @storage.stub!(:read).with('batata').and_return(image)
34
+ image.stub!(:to_blob).and_return("image data")
35
+ image.should_receive(:resize!).with("200x200")
36
+ image.should_receive(:destroy!)
37
+ @storage.stub!(:read).with("batata").and_return(image)
40
38
 
41
- get '/200x200/batata.jpg'
39
+ get "/200x200/batata.jpg"
42
40
 
43
41
  last_response.status.should == 200
44
42
  last_response.content_type == "image/jpg"
@@ -48,30 +46,7 @@ describe Mugshot::Application do
48
46
  it "should halt 404 when image doesn't exist" do
49
47
  @storage.stub!(:read).with("batata").and_return(nil)
50
48
 
51
- get '/200x200/batata.jpg'
52
-
53
- last_response.status.should == 404
54
- last_response.body.should be_empty
55
- end
56
- end
57
-
58
- describe "GET /:id" do
59
- it "should return original image" do
60
- image = mock(Mugshot::Image)
61
- image.stub!(:to_blob).and_return('image data')
62
- @storage.stub!(:read).with('batata').and_return(image)
63
-
64
- get '/batata.jpg'
65
-
66
- last_response.status.should == 200
67
- last_response.content_type == "image/jpg"
68
- last_response.body.should == "image data"
69
- end
70
-
71
- it "should halt 404 when image doesn't exist" do
72
- @storage.stub!(:read).with("batata").and_return(nil)
73
-
74
- get '/batata.jpg'
49
+ get "/200x200/batata.jpg"
75
50
 
76
51
  last_response.status.should == 404
77
52
  last_response.body.should be_empty
@@ -80,10 +55,17 @@ describe Mugshot::Application do
80
55
 
81
56
  describe "GET /" do
82
57
  it "should return ok as healthcheck" do
83
- get '/'
58
+ get "/"
84
59
 
85
60
  last_response.status.should == 200
86
- last_response.body.should == 'ok'
61
+ last_response.body.should == "ok"
62
+ end
63
+ end
64
+
65
+ describe "before" do
66
+ it "should cache response with max age of 1 day" do
67
+ get "/"
68
+ last_response.headers["Cache-Control"].should == "public, max-age=31557600"
87
69
  end
88
70
  end
89
71
  end
@@ -5,30 +5,76 @@ describe Mugshot::Image do
5
5
  @magick_image = mock(Magick::Image)
6
6
  Magick::Image.stub!(:read).and_return([@magick_image])
7
7
 
8
- @image = Mugshot::Image.new File.open("spec/files/test.jpg")
8
+ @image = Mugshot::Image.new(File.open("spec/files/test.jpg"))
9
9
  end
10
+
11
+ it 'should return image width and height' do
12
+ @magick_image.stub!(:columns).and_return(100)
13
+ @magick_image.stub!(:rows).and_return(200)
14
+
15
+ @image.width.should == 100
16
+ @image.height.should == 200
17
+ end
18
+
19
+ describe "to blob" do
20
+ before(:each) do
21
+ @magick_image.stub!(:strip!)
22
+ @magick_image.instance_eval do
23
+ def to_blob(&block)
24
+ block.call if block.present?
25
+ return 'blob_data'
26
+ end
27
+ end
28
+ end
29
+
30
+ it 'should return image as a blob using default options' do
31
+ @image.to_blob.should == 'blob_data'
32
+ end
33
+
34
+ it 'should return image as a blob using quality' do
35
+ @image.should_receive(:quality=).with(75)
36
+ @magick_image.instance_eval do
37
+ def to_blob(&block)
38
+ yield
39
+ return 'blob_data'
40
+ end
41
+ end
42
+
43
+ @image.to_blob(:quality => 75).should == 'blob_data'
44
+ end
45
+
46
+ it 'should return image as a blob using format' do
47
+ @image.should_receive(:format=).with('png')
48
+ @magick_image.instance_eval do
49
+ def to_blob(&block)
50
+ yield
51
+ return 'blob_data'
52
+ end
53
+ end
54
+
55
+ @image.to_blob(:format => :png).should == 'blob_data'
56
+ end
10
57
 
11
- it 'should return image as a blob' do
12
- blob_data = 'blob data'
13
- @magick_image.stub!(:to_blob).and_return(blob_data)
14
- @image.to_blob.should == blob_data
15
58
  end
16
59
 
17
60
  it "should resize image to given width and height" do
18
61
  @magick_image.should_receive(:resize!).with(300, 200)
19
- dim = Mugshot::Dimension.parse!("300x200")
20
- @image.resize! dim
62
+ @image.resize! "300x200"
21
63
  end
22
64
 
23
65
  it 'should resize image to fit given width' do
24
66
  @magick_image.should_receive(:resize_to_fit!).with(300, nil)
25
- dim = Mugshot::Dimension.parse!("300x")
26
- @image.resize! dim
67
+ @image.resize! "300x"
27
68
  end
28
69
 
29
70
  it 'should resize image to fit given height' do
30
71
  @magick_image.should_receive(:resize_to_fit!).with(nil, 200)
31
- dim = Mugshot::Dimension.parse!("x200")
32
- @image.resize! dim
72
+ @image.resize! "x200"
33
73
  end
74
+
75
+ it 'should destroy image' do
76
+ @magick_image.should_receive(:'destroy!')
77
+ @image.destroy!
78
+ end
79
+
34
80
  end
data/spec/spec.opts CHANGED
@@ -1,4 +1,5 @@
1
1
  --color
2
- --format progress
2
+ --format nested
3
3
  --loadby mtime
4
- --reverse
4
+ --reverse
5
+ --backtrace
data/spec/spec_helper.rb CHANGED
@@ -2,12 +2,6 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
 
4
4
  require 'rubygems'
5
-
6
- gems = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'gems_dev.yml'))
7
- gems.each do |depgem|
8
- gem "#{depgem[:name]}", "#{depgem[:version]}"
9
- end
10
-
11
5
  require 'mugshot'
12
6
 
13
7
  require 'spec'
metadata CHANGED
@@ -1,19 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mugshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Cain\xC3\xA3 Nunes"
8
8
  - "Fabr\xC3\xADcio Lopes"
9
- - Fernando Meyer
10
9
  - Guilherme Cirne
11
- - "Jos\xC3\xA9 Peleteiro"
10
+ - Jose Peleteiro
12
11
  autorequire:
13
12
  bindir: bin
14
13
  cert_chain: []
15
14
 
16
- date: 2009-12-04 00:00:00 -02:00
15
+ date: 2010-01-29 00:00:00 -02:00
17
16
  default_executable:
18
17
  dependencies:
19
18
  - !ruby/object:Gem::Dependency
@@ -22,29 +21,29 @@ dependencies:
22
21
  version_requirement:
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
- - - "="
24
+ - - ">="
26
25
  - !ruby/object:Gem::Version
27
- version: 2.3.5
26
+ version: "0"
28
27
  version:
29
28
  - !ruby/object:Gem::Dependency
30
- name: rmagick
29
+ name: sinatra
31
30
  type: :runtime
32
31
  version_requirement:
33
32
  version_requirements: !ruby/object:Gem::Requirement
34
33
  requirements:
35
- - - "="
34
+ - - ">="
36
35
  - !ruby/object:Gem::Version
37
- version: 2.12.2
36
+ version: 0.9.4
38
37
  version:
39
38
  - !ruby/object:Gem::Dependency
40
- name: sinatra
39
+ name: rmagick
41
40
  type: :runtime
42
41
  version_requirement:
43
42
  version_requirements: !ruby/object:Gem::Requirement
44
43
  requirements:
45
- - - "="
44
+ - - ">="
46
45
  - !ruby/object:Gem::Version
47
- version: 0.9.4
46
+ version: 2.12.2
48
47
  version:
49
48
  - !ruby/object:Gem::Dependency
50
49
  name: uuid
@@ -52,7 +51,7 @@ dependencies:
52
51
  version_requirement:
53
52
  version_requirements: !ruby/object:Gem::Requirement
54
53
  requirements:
55
- - - "="
54
+ - - ">="
56
55
  - !ruby/object:Gem::Version
57
56
  version: 2.0.2
58
57
  version:
@@ -62,9 +61,9 @@ dependencies:
62
61
  version_requirement:
63
62
  version_requirements: !ruby/object:Gem::Requirement
64
63
  requirements:
65
- - - "="
64
+ - - ">="
66
65
  - !ruby/object:Gem::Version
67
- version: 1.2.9
66
+ version: 1.3.0
68
67
  version:
69
68
  - !ruby/object:Gem::Dependency
70
69
  name: cucumber
@@ -72,35 +71,24 @@ dependencies:
72
71
  version_requirement:
73
72
  version_requirements: !ruby/object:Gem::Requirement
74
73
  requirements:
75
- - - "="
74
+ - - ">="
76
75
  - !ruby/object:Gem::Version
77
- version: 0.4.4
76
+ version: 0.6.2
78
77
  version:
79
78
  - !ruby/object:Gem::Dependency
80
79
  name: rack-test
81
80
  type: :development
82
81
  version_requirement:
83
- version_requirements: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - "="
86
- - !ruby/object:Gem::Version
87
- version: 0.5.1
88
- version:
89
- - !ruby/object:Gem::Dependency
90
- name: yard
91
- type: :development
92
- version_requirement:
93
82
  version_requirements: !ruby/object:Gem::Requirement
94
83
  requirements:
95
84
  - - ">="
96
85
  - !ruby/object:Gem::Version
97
- version: "0"
86
+ version: 0.5.1
98
87
  version:
99
- description: Image server
88
+ description: Dead simple image server
100
89
  email:
101
90
  - cainanunes@gmail.com
102
91
  - fabriciolopesvital@gmail.com
103
- - fmcamargo@gmail.com
104
92
  - gcirne@gmail.com
105
93
  - jose@peleteiro.net
106
94
  executables: []
@@ -109,44 +97,18 @@ extensions: []
109
97
 
110
98
  extra_rdoc_files:
111
99
  - LICENSE
112
- - README.rdoc
100
+ - README.md
113
101
  files:
114
- - .document
115
- - .gitignore
116
- - LICENSE
117
- - README.rdoc
118
- - Rakefile
119
- - VERSION
120
- - config.ru
121
- - features/retrieve_original_image.feature
122
- - features/retrieve_resized_image.feature
123
- - features/retrieve_resized_image_keeping_aspect_ratio.feature
124
- - features/step_definitions/general_steps.rb
125
- - features/step_definitions/retrieve_original_image_steps.rb
126
- - features/step_definitions/retrieve_resized_image_keeping_aspect_ratio_steps.rb
127
- - features/step_definitions/retrieve_resized_image_steps.rb
128
- - features/support/env.rb
129
- - features/support/files/test.jpg
130
- - gems.yml
131
- - gems_dev.yml
132
102
  - lib/mugshot.rb
133
103
  - lib/mugshot/application.rb
134
- - lib/mugshot/dimension.rb
135
104
  - lib/mugshot/fs_storage.rb
136
105
  - lib/mugshot/image.rb
137
106
  - lib/mugshot/public/crossdomain.xml
138
107
  - lib/mugshot/storage.rb
139
- - mugshot.gemspec
140
- - spec/files/test.jpg
141
- - spec/mugshot/application_spec.rb
142
- - spec/mugshot/dimension_spec.rb
143
- - spec/mugshot/fs_storage_spec.rb
144
- - spec/mugshot/image_spec.rb
145
- - spec/spec.opts
146
- - spec/spec_helper.rb
147
- - spec/test.html
108
+ - LICENSE
109
+ - README.md
148
110
  has_rdoc: true
149
- homepage: http://github.com/timebeta/mugshot
111
+ homepage: http://mugshot.ws
150
112
  licenses: []
151
113
 
152
114
  post_install_message:
@@ -172,10 +134,20 @@ rubyforge_project:
172
134
  rubygems_version: 1.3.5
173
135
  signing_key:
174
136
  specification_version: 3
175
- summary: Image server
137
+ summary: Dead simple image server
176
138
  test_files:
139
+ - spec/files/test.jpg
177
140
  - spec/mugshot/application_spec.rb
178
- - spec/mugshot/dimension_spec.rb
179
141
  - spec/mugshot/fs_storage_spec.rb
180
142
  - spec/mugshot/image_spec.rb
143
+ - spec/spec.opts
181
144
  - spec/spec_helper.rb
145
+ - spec/test.html
146
+ - features/retrieve_resized_image.feature
147
+ - features/retrieve_resized_image_keeping_aspect_ratio.feature
148
+ - features/step_definitions/all_steps.rb
149
+ - features/support/env.rb
150
+ - features/support/files/test.200x.jpg
151
+ - features/support/files/test.200x200.jpg
152
+ - features/support/files/test.jpg
153
+ - features/support/files/test.x200.jpg
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,22 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
- nbproject
21
-
22
- ## PROJECT::SPECIFIC
data/README.rdoc DELETED
@@ -1,18 +0,0 @@
1
- = farofus-mugshot
2
-
3
- Description goes here.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but
13
- bump version in a commit by itself I can ignore when I pull)
14
- * Send me a pull request. Bonus points for topic branches.
15
-
16
- == Copyright
17
-
18
- Copyright (c) 2009 Fernando Meyer. See LICENSE for details.
data/Rakefile DELETED
@@ -1,70 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- task :default => :spec
5
-
6
- begin
7
- require 'jeweler'
8
- namespace :gem do
9
- Jeweler::Tasks.new do |gem|
10
- gem.name = "mugshot"
11
- gem.summary = %Q{Image server}
12
- gem.description = %Q{Image server}
13
- gem.email = %w{cainanunes@gmail.com fabriciolopesvital@gmail.com fmcamargo@gmail.com gcirne@gmail.com jose@peleteiro.net}
14
- gem.homepage = "http://github.com/timebeta/mugshot"
15
- gem.authors = ["Cainã Nunes", "Fabrício Lopes", "Fernando Meyer", "Guilherme Cirne", "José Peleteiro"]
16
-
17
- ## dependencies
18
- gems = YAML.load_file 'gems.yml'
19
- gems.each do |depgem|
20
- gem.add_dependency(depgem[:name], depgem[:version])
21
- end
22
-
23
- ## developments dependencies
24
- gems = YAML.load_file 'gems_dev.yml'
25
- gems.each do |depgem|
26
- gem.add_development_dependency(depgem[:name], depgem[:version])
27
- end
28
-
29
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
30
- end
31
- end
32
- rescue LoadError
33
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
34
- end
35
-
36
- require 'spec/rake/spectask'
37
- Spec::Rake::SpecTask.new(:spec) do |spec|
38
- spec.libs << 'lib' << 'spec'
39
- spec.pattern = 'spec/**/*_spec.rb'
40
- spec.rcov = true
41
- spec.rcov_dir = 'doc/coverage'
42
- spec.rcov_opts = %w{--text-summary --failure-threshold 100 --exclude spec/*,gems/*,/usr/lib/ruby/*}
43
- end
44
- task :spec => 'gem:check_dependencies'
45
-
46
- require 'cucumber/rake/task'
47
- Cucumber::Rake::Task.new(:features)
48
- task :features => 'gem:check_dependencies'
49
-
50
- begin
51
- require 'reek/adapters/rake_task'
52
- Reek::RakeTask.new do |t|
53
- t.fail_on_error = true
54
- t.verbose = false
55
- t.source_files = 'lib/**/*.rb'
56
- end
57
- rescue LoadError
58
- task :reek do
59
- abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
60
- end
61
- end
62
-
63
- begin
64
- require 'yard'
65
- YARD::Rake::YardocTask.new
66
- rescue LoadError
67
- task :yardoc do
68
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
69
- end
70
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.5
data/config.ru DELETED
@@ -1,5 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.unshift(::File.expand_path(::File.join(::File.dirname(__FILE__), 'lib')))
3
- require 'mugshot'
4
-
5
- run Mugshot::Application.new(Mugshot::FSStorage.new('/tmp/mugshot'))
@@ -1,12 +0,0 @@
1
- Feature: Retrieve original image
2
-
3
- Scenario: Successful retrieval of original image
4
- When I upload an image
5
- And I ask for the original image
6
-
7
- Then I should get the original image
8
-
9
- Scenario: Image doesn't exist
10
- When I ask for an image that doesn't exist
11
-
12
- Then I should get a 404 response
@@ -1,15 +0,0 @@
1
- When /^I ask for the original image$/ do
2
- get "/#{@image_id}.jpg"
3
- @retrieved_image = last_response.body
4
- end
5
-
6
- When /^I ask for an image that doesn't exist$/ do
7
- get '/nonexistant.jpg'
8
- end
9
-
10
- Then /^I should get the original image$/ do
11
- require 'digest/md5'
12
- original_image = Magick::Image.read('features/support/files/test.jpg').first.to_blob
13
- @retrieved_image.should == original_image
14
- last_response.status.should == 200
15
- end
@@ -1,10 +0,0 @@
1
- Then /^I should get the (.*) resized image keeping the aspect ratio$/ do |size|
2
- dimension = Mugshot::Dimension.parse!(size)
3
-
4
- image = Magick::Image.read('features/support/files/test.jpg').first
5
- image.resize_to_fit!(*dimension.size)
6
- resized_image = image.to_blob
7
-
8
- @retrieved_image.should == resized_image
9
- last_response.status.should == 200
10
- end
@@ -1,10 +0,0 @@
1
- Then /^I should get the (.*) resized image$/ do |size|
2
- dimension = Mugshot::Dimension.parse!(size)
3
-
4
- image = Magick::Image.read('features/support/files/test.jpg').first
5
- image.resize!(*dimension.size)
6
- resized_image = image.to_blob
7
-
8
- @retrieved_image.should == resized_image
9
- last_response.status.should == 200
10
- end
data/gems.yml DELETED
@@ -1,11 +0,0 @@
1
- - :name: activesupport
2
- :version: = 2.3.5
3
-
4
- - :name: rmagick
5
- :version: = 2.12.2
6
-
7
- - :name: sinatra
8
- :version: = 0.9.4
9
-
10
- - :name: uuid
11
- :version: = 2.0.2
data/gems_dev.yml DELETED
@@ -1,11 +0,0 @@
1
- - :name: rspec
2
- :version: = 1.2.9
3
-
4
- - :name: cucumber
5
- :version: = 0.4.4
6
-
7
- - :name: rack-test
8
- :version: = 0.5.1
9
-
10
- - :name: yard
11
- :version: >= 0
@@ -1,27 +0,0 @@
1
- class Mugshot::Dimension
2
- attr_reader :width, :height
3
-
4
- def self.parse!(size)
5
- size = /(\d*)x(\d*)/.match(size)
6
- width = size[1].to_i if size[1].present?
7
- height = size[2].to_i if size[2].present?
8
- new(width, height)
9
- end
10
-
11
- def to_s
12
- "#{@width}x#{@height}"
13
- end
14
-
15
- def size
16
- return @width, @height
17
- end
18
-
19
- def will_keep_aspect?
20
- (@width == nil) || (@height == nil)
21
- end
22
-
23
- def initialize (width, height)
24
- @width = width
25
- @height = height
26
- end
27
- end
data/mugshot.gemspec DELETED
@@ -1,102 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{mugshot}
8
- s.version = "0.1.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Cain\303\243 Nunes", "Fabr\303\255cio Lopes", "Fernando Meyer", "Guilherme Cirne", "Jos\303\251 Peleteiro"]
12
- s.date = %q{2009-11-30}
13
- s.description = %q{Image server}
14
- s.email = ["cainanunes@gmail.com", "fabriciolopesvital@gmail.com", "fmcamargo@gmail.com", "gcirne@gmail.com", "jose@peleteiro.net"]
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "config.ru",
27
- "features/retrieve_original_image.feature",
28
- "features/retrieve_resized_image.feature",
29
- "features/retrieve_resized_image_keeping_aspect_ratio.feature",
30
- "features/step_definitions/general_steps.rb",
31
- "features/step_definitions/retrieve_original_image_steps.rb",
32
- "features/step_definitions/retrieve_resized_image_keeping_aspect_ratio_steps.rb",
33
- "features/step_definitions/retrieve_resized_image_steps.rb",
34
- "features/support/env.rb",
35
- "features/support/files/test.jpg",
36
- "gems.yml",
37
- "gems_dev.yml",
38
- "lib/mugshot.rb",
39
- "lib/mugshot/application.rb",
40
- "lib/mugshot/dimension.rb",
41
- "lib/mugshot/fs_storage.rb",
42
- "lib/mugshot/image.rb",
43
- "lib/mugshot/storage.rb",
44
- "mugshot.gemspec",
45
- "public/crossdomain.xml",
46
- "spec/files/test.jpg",
47
- "spec/mugshot/application_spec.rb",
48
- "spec/mugshot/dimension_spec.rb",
49
- "spec/mugshot/fs_storage_spec.rb",
50
- "spec/mugshot/image_spec.rb",
51
- "spec/spec.opts",
52
- "spec/spec_helper.rb",
53
- "spec/test.html"
54
- ]
55
- s.homepage = %q{http://github.com/timebeta/mugshot}
56
- s.rdoc_options = ["--charset=UTF-8"]
57
- s.require_paths = ["lib"]
58
- s.rubygems_version = %q{1.3.5}
59
- s.summary = %q{Image server}
60
- s.test_files = [
61
- "spec/mugshot/application_spec.rb",
62
- "spec/mugshot/dimension_spec.rb",
63
- "spec/mugshot/fs_storage_spec.rb",
64
- "spec/mugshot/image_spec.rb",
65
- "spec/spec_helper.rb"
66
- ]
67
-
68
- if s.respond_to? :specification_version then
69
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
70
- s.specification_version = 3
71
-
72
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
73
- s.add_runtime_dependency(%q<activesupport>, ["= 2.3.5"])
74
- s.add_runtime_dependency(%q<rmagick>, ["= 2.12.2"])
75
- s.add_runtime_dependency(%q<sinatra>, ["= 0.9.4"])
76
- s.add_runtime_dependency(%q<uuid>, ["= 2.0.2"])
77
- s.add_development_dependency(%q<rspec>, ["= 1.2.9"])
78
- s.add_development_dependency(%q<cucumber>, ["= 0.4.4"])
79
- s.add_development_dependency(%q<rack-test>, ["= 0.5.1"])
80
- s.add_development_dependency(%q<yard>, [">= 0"])
81
- else
82
- s.add_dependency(%q<activesupport>, ["= 2.3.5"])
83
- s.add_dependency(%q<rmagick>, ["= 2.12.2"])
84
- s.add_dependency(%q<sinatra>, ["= 0.9.4"])
85
- s.add_dependency(%q<uuid>, ["= 2.0.2"])
86
- s.add_dependency(%q<rspec>, ["= 1.2.9"])
87
- s.add_dependency(%q<cucumber>, ["= 0.4.4"])
88
- s.add_dependency(%q<rack-test>, ["= 0.5.1"])
89
- s.add_dependency(%q<yard>, [">= 0"])
90
- end
91
- else
92
- s.add_dependency(%q<activesupport>, ["= 2.3.5"])
93
- s.add_dependency(%q<rmagick>, ["= 2.12.2"])
94
- s.add_dependency(%q<sinatra>, ["= 0.9.4"])
95
- s.add_dependency(%q<uuid>, ["= 2.0.2"])
96
- s.add_dependency(%q<rspec>, ["= 1.2.9"])
97
- s.add_dependency(%q<cucumber>, ["= 0.4.4"])
98
- s.add_dependency(%q<rack-test>, ["= 0.5.1"])
99
- s.add_dependency(%q<yard>, [">= 0"])
100
- end
101
- end
102
-
@@ -1,25 +0,0 @@
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, nil]
10
- end
11
-
12
- it "should parse a single right value" do
13
- Mugshot::Dimension.parse!("x100").size.should == [nil, 100]
14
- end
15
-
16
- it "should keep aspect" do
17
- Mugshot::Dimension.parse!("x100").will_keep_aspect?.should be_true
18
- Mugshot::Dimension.parse!("100x").will_keep_aspect?.should be_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
-