meme_captain 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/config.ru CHANGED
@@ -7,4 +7,6 @@ require 'meme_captain'
7
7
  use Rack::ConditionalGet
8
8
  use Rack::Sendfile
9
9
 
10
+ use Rack::Static, :urls => %w{/tmp}, :root => 'public'
11
+
10
12
  run MemeCaptain::Server
@@ -15,8 +15,9 @@ module MemeCaptain
15
15
  end
16
16
 
17
17
  options = {
18
+ :density => 144,
18
19
  :fill => 'white',
19
- :font => 'Impact',
20
+ :font => 'Impact-Regular',
20
21
  :gravity => Magick::CenterGravity,
21
22
  :size => "#{img.page.width * 1.8}x#{img.page.height / 2}",
22
23
  :stroke => 'black',
@@ -27,14 +28,12 @@ module MemeCaptain
27
28
  line1_caption = Magick::Image.read("caption:#{line1.to_s.upcase}") {
28
29
  options.each { |k,v| self.send("#{k}=", v) }
29
30
  }
30
- line1_caption[0].resize!(line1_caption[0].columns / 2,
31
- line1_caption[0].rows / 2, Magick::LanczosFilter, 1.25)
31
+ line1_caption[0].resize!(0.5)
32
32
 
33
33
  line2_caption = Magick::Image.read("caption:#{line2.to_s.upcase}") {
34
34
  options.each { |k,v| self.send("#{k}=", v) }
35
35
  }
36
- line2_caption[0].resize!(line2_caption[0].columns / 2,
37
- line2_caption[0].rows / 2, Magick::LanczosFilter, 1.25)
36
+ line2_caption[0].resize!(0.5)
38
37
 
39
38
  text_layer = Magick::Image.new(img.page.width, img.page.height) {
40
39
  self.background_color = 'none'
@@ -2,6 +2,7 @@ require 'digest/sha1'
2
2
  require 'uri'
3
3
 
4
4
  require 'curb'
5
+ require 'json'
5
6
  require 'sinatra/base'
6
7
 
7
8
  require 'meme_captain'
@@ -13,12 +14,6 @@ module MemeCaptain
13
14
  ImageExts = %w{.jpeg .gif .png}
14
15
 
15
16
  get '/' do
16
- @img_url = if params[:u]
17
- uri = URI(request.url)
18
- uri.path += 'i'
19
- uri.to_s
20
- end
21
-
22
17
  @u = params[:u]
23
18
  @tt= params[:tt]
24
19
  @tb = params[:tb]
@@ -26,16 +21,18 @@ module MemeCaptain
26
21
  erb :index
27
22
  end
28
23
 
29
- get '/i' do
30
- @processed_cache ||= MemeCaptain::FilesystemCache.new(
31
- 'img_cache/processed')
24
+ def gen(params)
25
+ @processed_cache ||= MemeCaptain::FilesystemCache.new('public/tmp')
32
26
  @source_cache ||= MemeCaptain::FilesystemCache.new('img_cache/source')
33
27
 
34
28
  processed_id = Digest::SHA1.hexdigest(params.sort.map(&:join).join)
35
- processed_cache_path = @processed_cache.get_path(processed_id, ImageExts) {
29
+ @processed_cache.get_path(processed_id, ImageExts) {
36
30
  source_id = Digest::SHA1.hexdigest(params[:u])
37
31
  source_img_data = @source_cache.get_data(source_id, ImageExts) {
38
- Curl::Easy.perform(params[:u]).body_str
32
+ curl = Curl::Easy.perform(params[:u]) do |c|
33
+ c.useragent = 'Meme Captain http://memecaptain.com/'
34
+ end
35
+ curl.body_str
39
36
  }
40
37
 
41
38
  meme_img = MemeCaptain.meme(source_img_data, params[:tt], params[:tb])
@@ -49,12 +46,32 @@ module MemeCaptain
49
46
  end
50
47
  }
51
48
  }
49
+ end
52
50
 
53
- headers = {
54
- 'Content-Type' => MIME::Types.type_for(processed_cache_path)[0].to_s,
55
- }
51
+ get '/g' do
52
+ content_type :json
53
+
54
+ processed_cache_path = gen(params)
55
+
56
+ temp_url = URI(request.url)
57
+ temp_url.path = processed_cache_path.sub('public', '')
58
+ temp_url.query = nil
59
+
60
+ perm_url = URI(request.url)
61
+ perm_url.path = '/i'
62
+
63
+ {
64
+ 'tempUrl' => temp_url.to_s,
65
+ 'permUrl' => perm_url.to_s,
66
+ }.to_json
67
+ end
68
+
69
+ get '/i' do
70
+ processed_cache_path = gen(params)
71
+
72
+ content_type MIME::Types.type_for(processed_cache_path)[0].to_s
56
73
 
57
- [ 200, headers, MemeCaptain::FileBody.new(processed_cache_path) ]
74
+ MemeCaptain::FileBody.new(processed_cache_path)
58
75
  end
59
76
 
60
77
  helpers do
data/meme_captain.gemspec CHANGED
@@ -4,17 +4,16 @@ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'meme_captain'
7
- s.version = '0.0.5'
7
+ s.version = '0.0.6'
8
8
  s.summary = 'create meme images'
9
9
  s.description = s.summary
10
10
  s.homepage = 'https://github.com/mmb/meme_captain'
11
11
  s.authors = ['Matthew M. Boedicker']
12
12
  s.email = %w{matthewm@boedicker.org}
13
13
 
14
- s.required_rubygems_version = '>= 1.3.6'
15
-
16
14
  %w{
17
15
  curb
16
+ json
18
17
  mime-types
19
18
  rack
20
19
  rmagick
File without changes
data/views/index.erb CHANGED
@@ -12,10 +12,7 @@
12
12
 
13
13
  <p>Add text to images from the internet.</p>
14
14
 
15
- <% if @img_url %>
16
- <p><a href="<%= h @img_url %>"><img src="<%= h @img_url %>" /></a></p>
17
- <p><a href="<%= h @img_url %>"><%= h @img_url %></a></p>
18
- <% end %>
15
+ <div id="img"></div>
19
16
 
20
17
  <form action="" method="get">
21
18
 
@@ -45,10 +42,48 @@
45
42
 
46
43
  </form>
47
44
 
45
+ <img src="http://memecaptain.com/bear_grylls_thumb.jpg" onClick="$('#u').val('http://memecaptain.com/bear_grylls.jpg'); return false;" />
46
+
47
+ <img src="http://memecaptain.com/most_interesting_thumb.jpg" onClick="$('#u').val('http://memecaptain.com/most_interesting.jpg'); return false;" />
48
+
49
+ <img src="http://memecaptain.com/philosoraptor_thumb.jpg" onClick="$('#u').val('http://memecaptain.com/philosoraptor.jpg'); return false;" />
50
+
51
+ <img src="http://memecaptain.com/scumbag_steve_thumb.jpg" onClick="$('#u').val('http://memecaptain.com/scumbag_steve.jpg'); return false;" />
52
+
53
+ <img src="http://memecaptain.com/town_crier_thumb.jpg" onClick="$('#u').val('http://memecaptain.com/town_crier.jpg'); return false;" />
54
+
55
+ <img src="http://memecaptain.com/troll_face_thumb.jpg" onClick="$('#u').val('http://memecaptain.com/troll_face.jpg'); return false;" />
56
+
57
+ <img src="http://memecaptain.com/yao_ming_thumb.jpg" onClick="$('#u').val('http://memecaptain.com/yao_ming.jpg'); return false;" />
58
+
59
+ <img src="http://memecaptain.com/y_u_no_thumb.jpg" onClick="$('#u').val('http://memecaptain.com/y_u_no.jpg'); return false;" />
60
+
48
61
  <p>by Matthew M. Boedicker <a href="mailto:matthewm@boedicker.org">matthewm@boedicker.org</a></p>
49
62
 
50
63
  <p><a href="https://github.com/mmb/meme_captain">source code</a></p>
51
64
 
65
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
66
+ <script>
67
+ $(function () {
68
+ if (window.location.search.match(/u=[^&$]/)) {
69
+ var imgDiv = $('#img');
70
+
71
+ imgDiv.append($('<p />').append('Creating image ...'));
72
+
73
+ $.get('/g' + window.location.search, function(data) {
74
+ var img = $('<img />').attr('src', data.tempUrl),
75
+ tempLink = $('<a />').attr('href', data.tempUrl).append(data.tempUrl),
76
+ permLink = $('<a />').attr('href', data.permUrl).append(data.permUrl);
77
+
78
+ imgDiv.empty().append(
79
+ img).append(
80
+ $('<p />').append('Temporary image url: ').append(tempLink)).append(
81
+ $('<p />').append('Permanent image url: ').append(permLink));
82
+ });
83
+ }
84
+ });
85
+ </script>
86
+
52
87
  </body>
53
88
 
54
89
  </html>
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meme_captain
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew M. Boedicker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-29 00:00:00 -04:00
18
+ date: 2011-05-15 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -33,7 +33,7 @@ dependencies:
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: mime-types
36
+ name: json
37
37
  prerelease: false
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
@@ -47,7 +47,7 @@ dependencies:
47
47
  type: :runtime
48
48
  version_requirements: *id002
49
49
  - !ruby/object:Gem::Dependency
50
- name: rack
50
+ name: mime-types
51
51
  prerelease: false
52
52
  requirement: &id003 !ruby/object:Gem::Requirement
53
53
  none: false
@@ -61,7 +61,7 @@ dependencies:
61
61
  type: :runtime
62
62
  version_requirements: *id003
63
63
  - !ruby/object:Gem::Dependency
64
- name: rmagick
64
+ name: rack
65
65
  prerelease: false
66
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
67
  none: false
@@ -75,7 +75,7 @@ dependencies:
75
75
  type: :runtime
76
76
  version_requirements: *id004
77
77
  - !ruby/object:Gem::Dependency
78
- name: sinatra
78
+ name: rmagick
79
79
  prerelease: false
80
80
  requirement: &id005 !ruby/object:Gem::Requirement
81
81
  none: false
@@ -88,6 +88,20 @@ dependencies:
88
88
  version: "0"
89
89
  type: :runtime
90
90
  version_requirements: *id005
91
+ - !ruby/object:Gem::Dependency
92
+ name: sinatra
93
+ prerelease: false
94
+ requirement: &id006 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ type: :runtime
104
+ version_requirements: *id006
91
105
  description: create meme images
92
106
  email:
93
107
  - matthewm@boedicker.org
@@ -102,7 +116,6 @@ files:
102
116
  - COPYING
103
117
  - README.textile
104
118
  - config.ru
105
- - img_cache/processed/.gitignore
106
119
  - img_cache/source/.gitignore
107
120
  - lib/meme_captain.rb
108
121
  - lib/meme_captain/file_body.rb
@@ -111,6 +124,7 @@ files:
111
124
  - lib/meme_captain/mime_type.rb
112
125
  - lib/meme_captain/server.rb
113
126
  - meme_captain.gemspec
127
+ - public/tmp/.gitignore
114
128
  - views/index.erb
115
129
  has_rdoc: true
116
130
  homepage: https://github.com/mmb/meme_captain
@@ -135,12 +149,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - ">="
137
151
  - !ruby/object:Gem::Version
138
- hash: 23
152
+ hash: 3
139
153
  segments:
140
- - 1
141
- - 3
142
- - 6
143
- version: 1.3.6
154
+ - 0
155
+ version: "0"
144
156
  requirements: []
145
157
 
146
158
  rubyforge_project: