httpthumbnailer 1.2.0 → 1.3.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.
Files changed (57) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +4 -3
  3. data/Gemfile.lock +12 -12
  4. data/README.md +242 -68
  5. data/Rakefile +8 -2
  6. data/VERSION +1 -1
  7. data/bin/httpthumbnailer +35 -7
  8. data/lib/httpthumbnailer/error_reporter.rb +4 -2
  9. data/lib/httpthumbnailer/ownership.rb +54 -0
  10. data/lib/httpthumbnailer/plugin.rb +87 -0
  11. data/lib/httpthumbnailer/plugin/thumbnailer.rb +22 -427
  12. data/lib/httpthumbnailer/plugin/thumbnailer/service.rb +163 -0
  13. data/lib/httpthumbnailer/plugin/thumbnailer/service/built_in_plugins.rb +134 -0
  14. data/lib/httpthumbnailer/plugin/thumbnailer/service/images.rb +295 -0
  15. data/lib/httpthumbnailer/plugin/thumbnailer/service/magick.rb +208 -0
  16. data/lib/httpthumbnailer/thumbnail_specs.rb +130 -37
  17. data/lib/httpthumbnailer/thumbnailer.rb +29 -11
  18. metadata +30 -81
  19. data/.rspec +0 -1
  20. data/features/httpthumbnailer.feature +0 -24
  21. data/features/identify.feature +0 -31
  22. data/features/step_definitions/httpthumbnailer_steps.rb +0 -159
  23. data/features/support/env.rb +0 -106
  24. data/features/support/test-large.jpg +0 -0
  25. data/features/support/test-transparent.png +0 -0
  26. data/features/support/test.jpg +0 -0
  27. data/features/support/test.png +0 -0
  28. data/features/support/test.txt +0 -1
  29. data/features/thumbnail.feature +0 -269
  30. data/features/thumbnails.feature +0 -158
  31. data/httpthumbnailer.gemspec +0 -121
  32. data/load_test/extralarge.jpg +0 -0
  33. data/load_test/large.jpg +0 -0
  34. data/load_test/large.png +0 -0
  35. data/load_test/load_test-374846090-1.1.0-rc1-identify-only.csv +0 -3
  36. data/load_test/load_test-374846090-1.1.0-rc1.csv +0 -11
  37. data/load_test/load_test-cd9679c.csv +0 -10
  38. data/load_test/load_test-v0.3.1.csv +0 -10
  39. data/load_test/load_test.jmx +0 -733
  40. data/load_test/medium.jpg +0 -0
  41. data/load_test/small.jpg +0 -0
  42. data/load_test/soak_test-ac0c6bcbe5e-broken-libjpeg-tatoos.csv +0 -11
  43. data/load_test/soak_test-cd9679c.csv +0 -10
  44. data/load_test/soak_test-f98334a-tatoos.csv +0 -11
  45. data/load_test/soak_test.jmx +0 -754
  46. data/load_test/tiny.jpg +0 -0
  47. data/load_test/v0.0.13-loading.csv +0 -7
  48. data/load_test/v0.0.13.csv +0 -7
  49. data/load_test/v0.0.14-no-optimization.csv +0 -10
  50. data/load_test/v0.0.14.csv +0 -10
  51. data/spec/image_processing_spec.rb +0 -148
  52. data/spec/plugin_thumbnailer_spec.rb +0 -318
  53. data/spec/spec_helper.rb +0 -14
  54. data/spec/support/square_even.png +0 -0
  55. data/spec/support/square_odd.png +0 -0
  56. data/spec/support/test_image.rb +0 -16
  57. data/spec/thumbnail_specs_spec.rb +0 -43
@@ -1,106 +0,0 @@
1
- require 'bundler'
2
- begin
3
- Bundler.setup(:default, :development)
4
- rescue Bundler::BundlerError => e
5
- $stderr.puts e.message
6
- $stderr.puts "Run `bundle install` to install missing gems"
7
- exit e.status_code
8
- end
9
-
10
-
11
- require 'rspec/expectations'
12
- require 'multipart_parser/reader'
13
- require 'daemon'
14
- require 'timeout'
15
- require 'httpclient'
16
- require "open3"
17
- require "thread"
18
- require 'RMagick'
19
- require 'json'
20
-
21
- def gem_dir
22
- Pathname.new(__FILE__).dirname + '..' + '..'
23
- end
24
-
25
- def features_dir
26
- gem_dir + 'features'
27
- end
28
-
29
- def support_dir
30
- features_dir + 'support'
31
- end
32
-
33
- def script(file)
34
- gem_dir + 'bin' + file
35
- end
36
-
37
- def part_no(part)
38
- case part
39
- when 'first' then 0
40
- when 'second' then 1
41
- when 'third' then 2
42
- else fail "add more parts?"
43
- end
44
- end
45
-
46
- def http_client
47
- client = HTTPClient.new
48
- #client.debug_dev = STDOUT
49
- client
50
- end
51
-
52
- @@running_cmd = {}
53
- def start_server(cmd, pid_file, log_file, test_url)
54
- if @@running_cmd[pid_file]
55
- return if @@running_cmd[pid_file] == cmd
56
- stop_server(pid_file)
57
- end
58
-
59
- fork do
60
- Daemon.daemonize(pid_file, log_file)
61
- log_file = Pathname.new(log_file)
62
- log_file.truncate(0) if log_file.exist?
63
- exec(cmd)
64
- end
65
-
66
- @@running_cmd[pid_file] = cmd
67
-
68
- ppid = Process.pid
69
- at_exit do
70
- stop_server(pid_file) if Process.pid == ppid
71
- end
72
-
73
- Timeout.timeout(6) do
74
- begin
75
- http_client.get_content test_url
76
- rescue Errno::ECONNREFUSED
77
- sleep 0.1
78
- retry
79
- end
80
- end
81
- end
82
-
83
- def stop_server(pid_file)
84
- pid_file = Pathname.new(pid_file)
85
- return unless pid_file.exist?
86
-
87
- STDERR.puts http_client.get_content("http://localhost:3100/stats")
88
- pid = pid_file.read.strip.to_i
89
-
90
- Timeout.timeout(20) do
91
- begin
92
- loop do
93
- Process.kill("TERM", pid)
94
- sleep 0.1
95
- end
96
- rescue Errno::ESRCH
97
- pid_file.unlink
98
- end
99
- end
100
- end
101
-
102
- After do |scenario|
103
- step 'there should be no leaked images'
104
- step 'there should be maximum 3 images loaded during single request'
105
- end
106
-
Binary file
Binary file
@@ -1 +0,0 @@
1
- hello world
@@ -1,269 +0,0 @@
1
- Feature: Generating single thumbnail with PUT request
2
- In order to generate a single image thumbnail
3
- A user must PUT an image to URL in format
4
- /thumbnail[/<thumbnail type>,<width>,<height>,<format>
5
-
6
- Background:
7
- Given httpthumbnailer server is running at http://localhost:3100/
8
-
9
- @test
10
- Scenario: Single thumbnail
11
- Given test.jpg file content as request body
12
- When I do PUT request http://localhost:3100/thumbnail/crop,16,24,png
13
- Then response status should be 200
14
- Then response should contain PNG image of size 16x24
15
- And that image should be 8 bit image
16
- And Content-Type header should be image/png
17
- And X-Image-Width header should be 16
18
- And X-Image-Height header should be 24
19
- When I do PUT request http://localhost:3100/thumbnail/crop,16,24,jpeg
20
- Then response status should be 200
21
- Then response should contain JPEG image of size 16x24
22
- And that image should be 8 bit image
23
- And Content-Type header should be image/jpeg
24
- And X-Image-Width header should be 16
25
- And X-Image-Height header should be 24
26
-
27
- @transparent
28
- Scenario: Transparent image to JPEG handling - default background color white
29
- Given test-transparent.png file content as request body
30
- When I do PUT request http://localhost:3100/thumbnail/fit,128,128,jpeg
31
- Then response status should be 200
32
- And response will be saved as test-transparent-default.png for human inspection
33
- Then response should contain JPEG image of size 128x128
34
- And that image pixel at 32x32 should be of color white
35
-
36
- @input_format
37
- Scenario: Thumbnails of format input should have same format as input image
38
- Given test.jpg file content as request body
39
- When I do PUT request http://localhost:3100/thumbnail/crop,4,8,input
40
- Then response status should be 200
41
- Then response should contain JPEG image of size 4x8
42
- And response mime type should be image/jpeg
43
- Given test.png file content as request body
44
- When I do PUT request http://localhost:3100/thumbnail/crop,4,8,input
45
- Then response status should be 200
46
- Then response should contain PNG image of size 4x8
47
- And that image should be 8 bit image
48
- And response mime type should be image/png
49
-
50
- @input_size
51
- Scenario: Thumbnails of width or height input should have input image width or height
52
- Given test.jpg file content as request body
53
- When I do PUT request http://localhost:3100/thumbnail/crop,input,16,png
54
- Then response status should be 200
55
- Then response should contain PNG image of size 509x16
56
- And response mime type should be image/png
57
- When I do PUT request http://localhost:3100/thumbnail/crop,4,input,png
58
- Then response status should be 200
59
- Then response should contain PNG image of size 4x719
60
- And response mime type should be image/png
61
- When I do PUT request http://localhost:3100/thumbnail/crop,input,input,png
62
- Then response status should be 200
63
- Then response should contain PNG image of size 509x719
64
- And response mime type should be image/png
65
-
66
- @fit
67
- Scenario: Fit thumbnailing method
68
- Given test.jpg file content as request body
69
- When I do PUT request http://localhost:3100/thumbnail/fit,128,128,png
70
- Then response status should be 200
71
- Then response should contain PNG image of size 91x128
72
- Given test.jpg file content as request body
73
- When I do PUT request http://localhost:3100/thumbnail/fit,1024,1024,png
74
- Then response status should be 200
75
- Then response should contain PNG image of size 725x1024
76
-
77
- @limit
78
- Scenario: Limit thumbnailing method should reduce image size when needed
79
- Given test.jpg file content as request body
80
- When I do PUT request http://localhost:3100/thumbnail/limit,128,128,png
81
- Then response status should be 200
82
- Then response should contain PNG image of size 91x128
83
- Given test.jpg file content as request body
84
- When I do PUT request http://localhost:3100/thumbnail/limit,1024,1024,png
85
- Then response status should be 200
86
- Then response should contain PNG image of size 509x719
87
-
88
- @pad @transparent
89
- Scenario: Pad thumbnailing method - default background color white
90
- Given test.jpg file content as request body
91
- When I do PUT request http://localhost:3100/thumbnail/pad,128,128,png
92
- Then response status should be 200
93
- And response will be saved as test-pad.png for human inspection
94
- Then response should contain PNG image of size 128x128
95
- And that image pixel at 2x2 should be of color white
96
-
97
- @pad @transparent
98
- Scenario: Pad thumbnailing method with specified background color
99
- Given test.jpg file content as request body
100
- When I do PUT request http://localhost:3100/thumbnail/pad,128,128,png,background-color:green
101
- Then response status should be 200
102
- And response will be saved as test-pad-background-color.png for human inspection
103
- Then response should contain PNG image of size 128x128
104
- And that image pixel at 2x2 should be of color green
105
-
106
- @error_handling
107
- Scenario: Reporitng of unsupported media type
108
- Given test.txt file content as request body
109
- When I do PUT request http://localhost:3100/thumbnail/crop,128,128,png
110
- Then response status should be 415
111
- And response content type should be text/plain
112
- And response body should be CRLF endend lines like
113
- """
114
- unsupported media type: no decode delegate for this image format
115
- """
116
-
117
- @error_handling
118
- Scenario: Reporitng of bad thumbanil spec format - bad dimension value
119
- Given test.jpg file content as request body
120
- When I do PUT request http://localhost:3100/thumbnail/crop,128,bogous,png
121
- Then response status should be 400
122
- And response content type should be text/plain
123
- And response body should be CRLF endend lines
124
- """
125
- bad dimension value: bogous
126
- """
127
-
128
- @error_handling
129
- Scenario: Reporitng of bad thumbanil spec format - missing param
130
- Given test.jpg file content as request body
131
- When I do PUT request http://localhost:3100/thumbnail/crop,128,png
132
- Then response status should be 400
133
- And response content type should be text/plain
134
- And response body should be CRLF endend lines
135
- """
136
- missing argument in: crop,128,png
137
- """
138
-
139
- @error_handling
140
- Scenario: Reporitng of bad thumbanil spec format - bad options format
141
- Given test.jpg file content as request body
142
- When I do PUT request http://localhost:3100/thumbnail/crop,128,128,png,fas-xyz
143
- Then response status should be 400
144
- And response content type should be text/plain
145
- And response body should be CRLF endend lines
146
- """
147
- missing option key or value in: fas-xyz
148
- """
149
-
150
- @error_handling
151
- Scenario: Reporitng of bad operation value
152
- Given test.jpg file content as request body
153
- When I do PUT request http://localhost:3100/thumbnail/blah,128,128,png
154
- Then response status should be 400
155
- And response content type should be text/plain
156
- And response body should be CRLF endend lines
157
- """
158
- thumbnail method 'blah' is not supported
159
- """
160
-
161
- @error_handling
162
- Scenario: Reporitng of image thumbnailing errors
163
- Given test.jpg file content as request body
164
- When I do PUT request http://localhost:3100/thumbnail/crop,0,0,jpeg
165
- Then response status should be 400
166
- And response content type should be text/plain
167
- And response body should be CRLF endend lines
168
- """
169
- at least one image dimension is zero: 0x0
170
- """
171
-
172
- @error_handling
173
- Scenario: Reporitng of bad color value
174
- Given test.jpg file content as request body
175
- When I do PUT request http://localhost:3100/thumbnail/pad,240,200,input,background-color:ff11
176
- Then response status should be 400
177
- And response content type should be text/plain
178
- And response body should be CRLF endend lines
179
- """
180
- invalid color name: ff11
181
- """
182
-
183
- @optimization
184
- Scenario: Handing of large image data - possible thanks to loading size optimization
185
- Given test-large.jpg file content as request body
186
- When I do PUT request http://localhost:3100/thumbnail/crop,16,16,png
187
- Then response status should be 200
188
- Then response should contain PNG image of size 16x16
189
-
190
- @resources
191
- Scenario: Memory limits exhausted while loading - no loading optimization possible
192
- Given test-large.jpg file content as request body
193
- When I do PUT request http://localhost:3100/thumbnail/crop,7000,7000,png
194
- Then response status should be 413
195
- And response content type should be text/plain
196
- And response body should be CRLF endend lines like
197
- """
198
- image too large: cache resources exhausted
199
- """
200
-
201
- @resources
202
- Scenario: Memory limits exhausted while thumbnailing
203
- Given test.jpg file content as request body
204
- When I do PUT request http://localhost:3100/thumbnail/crop,16000,16000,jpeg
205
- Then response status should be 413
206
- And response content type should be text/plain
207
- And response body should be CRLF endend lines like
208
- """
209
- image too large: cache resources exhausted
210
- """
211
-
212
- @quality
213
- Scenario: Quality option - JPEG
214
- Given test.jpg file content as request body
215
- When I do PUT request http://localhost:3100/thumbnail/crop,32,32,jpeg,quality:10
216
- When I save response body
217
- When I do PUT request http://localhost:3100/thumbnail/crop,32,32,jpeg,quality:80
218
- Then saved response body will be smaller than response body
219
- When I save response body
220
- When I do PUT request http://localhost:3100/thumbnail/crop,32,32,jpeg,quality:90
221
- Then saved response body will be smaller than response body
222
-
223
- @quality
224
- Scenario: Quality option - JPEG - default 85
225
- Given test.jpg file content as request body
226
- When I do PUT request http://localhost:3100/thumbnail/crop,32,32,jpeg,quality:84
227
- When I save response body
228
- Then response mime type should be image/jpeg
229
- When I do PUT request http://localhost:3100/thumbnail/crop,32,32,jpeg
230
- Then saved response body will be smaller than response body
231
- Then response mime type should be image/jpeg
232
- When I save response body
233
- When I do PUT request http://localhost:3100/thumbnail/crop,32,32,jpeg,quality:86
234
- Then saved response body will be smaller than response body
235
- Then response mime type should be image/jpeg
236
-
237
- @quality
238
- Scenario: Quality option - PNG (XY where X - zlib compresion level, Y - filter)
239
- Given test.jpg file content as request body
240
- When I do PUT request http://localhost:3100/thumbnail/crop,128,128,png,quality:90
241
- When I save response body
242
- Then response mime type should be image/png
243
- When I do PUT request http://localhost:3100/thumbnail/crop,128,128,png,quality:50
244
- Then saved response body will be smaller than response body
245
- Then response mime type should be image/png
246
- When I save response body
247
- When I do PUT request http://localhost:3100/thumbnail/crop,128,128,png,quality:10
248
- Then saved response body will be smaller than response body
249
- Then response mime type should be image/png
250
-
251
- @hint @input
252
- Scenario: Hint on input image mime type
253
- Given test.jpg file content as request body
254
- When I do PUT request http://localhost:3100/thumbnail/crop,16,16,png
255
- Then response status should be 200
256
- And X-Input-Image-Mime-Type header should be image/jpeg
257
- Given test.png file content as request body
258
- When I do PUT request http://localhost:3100/thumbnail/crop,16,16,png
259
- Then response status should be 200
260
- And X-Input-Image-Mime-Type header should be image/png
261
-
262
- @hint @input
263
- Scenario: Hint on input image size
264
- Given test-large.jpg file content as request body
265
- When I do PUT request http://localhost:3100/thumbnail/crop,16,16,png
266
- Then response status should be 200
267
- And X-Input-Image-Width header should be 9911
268
- And X-Input-Image-Height header should be 14000
269
-
@@ -1,158 +0,0 @@
1
- Feature: Generating set of thumbnails with single PUT request
2
- In order to generate a set of image thumbnails
3
- A user must PUT an image to URL in format
4
- /thumbnails[/<thumbnail type>,<width>,<height>,<format>[,<option key>:<option value>]+]+
5
-
6
- Background:
7
- Given httpthumbnailer server is running at http://localhost:3100/
8
-
9
- @multipart
10
- Scenario: Single thumbnail
11
- Given test.jpg file content as request body
12
- When I do PUT request http://localhost:3100/thumbnails/crop,16,24,png
13
- Then response status should be 200
14
- And I should get multipart response
15
- Then first part should contain PNG image of size 16x24
16
- And that image should be 8 bit image
17
- And first part Content-Type header should be image/png
18
- And first part X-Image-Width header should be 16
19
- And first part X-Image-Height header should be 24
20
-
21
- @multipart
22
- Scenario: Multiple thumbnails
23
- Given test.jpg file content as request body
24
- When I do PUT request http://localhost:3100/thumbnails/crop,16,16,png/crop,4,8,jpeg/crop,16,32,jpeg
25
- Then response status should be 200
26
- And I should get multipart response
27
- Then first part should contain PNG image of size 16x16
28
- And first part Content-Type header should be image/png
29
- And first part X-Image-Width header should be 16
30
- And first part X-Image-Height header should be 16
31
- Then second part should contain JPEG image of size 4x8
32
- And second part Content-Type header should be image/jpeg
33
- And second part X-Image-Width header should be 4
34
- And second part X-Image-Height header should be 8
35
- Then third part should contain JPEG image of size 16x32
36
- And third part Content-Type header should be image/jpeg
37
- And third part X-Image-Width header should be 16
38
- And third part X-Image-Height header should be 32
39
-
40
- @input_size
41
- Scenario: Thumbnails of width or height input should have input image width or height
42
- Given test.jpg file content as request body
43
- When I do PUT request http://localhost:3100/thumbnails/crop,input,16,jpeg/crop,4,input,png/crop,input,input,png
44
- Then response status should be 200
45
- And I should get multipart response
46
- Then first part should contain JPEG image of size 509x16
47
- Then second part should contain PNG image of size 4x719
48
- Then third part should contain PNG image of size 509x719
49
-
50
- @leaking
51
- Scenario: Image leaking on error
52
- Given test.jpg file content as request body
53
- When I do PUT request http://localhost:3100/thumbnails/crop,0,0,png/fit,0,0,jpeg/pad,0,0,jpeg
54
- Then response status should be 200
55
- And I should get multipart response
56
- And first part Content-Type header should be text/plain
57
- And second part Content-Type header should be text/plain
58
- And third part Content-Type header should be text/plain
59
-
60
- @error_handling
61
- Scenario: Reporitng of bad thumbanil spec format - bad dimension value
62
- Given test.jpg file content as request body
63
- When I do PUT request http://localhost:3100/thumbnails/crop,4,4,png/crop,128,bogous,png
64
- Then response status should be 400
65
- And response content type should be text/plain
66
- And response body should be CRLF endend lines
67
- """
68
- bad dimension value: bogous
69
- """
70
-
71
- @error_handling
72
- Scenario: Reporitng of bad thumbanil spec format - missing param
73
- Given test.jpg file content as request body
74
- When I do PUT request http://localhost:3100/thumbnails/crop,4,4,png/crop,128,png
75
- Then response status should be 400
76
- And response content type should be text/plain
77
- And response body should be CRLF endend lines
78
- """
79
- missing argument in: crop,128,png
80
- """
81
-
82
- @error_handling
83
- Scenario: Reporitng of bad thumbanil spec format - bad options format
84
- Given test.jpg file content as request body
85
- When I do PUT request http://localhost:3100/thumbnails/crop,4,4,png/crop,128,128,png,fas-fda
86
- Then response status should be 400
87
- And response content type should be text/plain
88
- And response body should be CRLF endend lines
89
- """
90
- missing option key or value in: fas-fda
91
- """
92
-
93
- @error_handling
94
- Scenario: Reporitng of bad operation value
95
- Given test.jpg file content as request body
96
- When I do PUT request http://localhost:3100/thumbnails/crop,4,4,png/blah,128,128,png
97
- Then response status should be 200
98
- And I should get multipart response
99
- And second part Content-Type header should be text/plain
100
- And second part body should be CRLF endend lines
101
- """
102
- thumbnail method 'blah' is not supported
103
- """
104
- And second part Status header should be 400
105
-
106
- @error_handling
107
- Scenario: Reporitng of image thumbnailing errors
108
- Given test.jpg file content as request body
109
- When I do PUT request http://localhost:3100/thumbnails/crop,16,16,png/crop,0,0,jpeg/crop,16,32,jpeg
110
- Then response status should be 200
111
- And I should get multipart response
112
- Then first part should contain PNG image of size 16x16
113
- And first part Content-Type header should be image/png
114
- And second part Content-Type header should be text/plain
115
- And second part body should be CRLF endend lines
116
- """
117
- at least one image dimension is zero: 0x0
118
- """
119
- And second part Status header should be 400
120
- Then third part should contain JPEG image of size 16x32
121
- And third part Content-Type header should be image/jpeg
122
-
123
- @resources
124
- Scenario: Memory limits exhausted while thumbnailing
125
- Given test.jpg file content as request body
126
- When I do PUT request http://localhost:3100/thumbnails/crop,16,16,png/crop,16000,16000,jpeg/crop,16,32,jpeg
127
- Then response status should be 200
128
- And I should get multipart response
129
- Then first part should contain PNG image of size 16x16
130
- And first part Content-Type header should be image/png
131
- And second part Content-Type header should be text/plain
132
- And second part body should be CRLF endend lines like
133
- """
134
- image too large: cache resources exhausted
135
- """
136
- And second part Status header should be 413
137
- Then third part should contain JPEG image of size 16x32
138
- And third part Content-Type header should be image/jpeg
139
-
140
- @hint @input
141
- Scenario: Hint on input image mime type
142
- Given test.jpg file content as request body
143
- When I do PUT request http://localhost:3100/thumbnails/crop,16,16,png
144
- Then response status should be 200
145
- And X-Input-Image-Mime-Type header should be image/jpeg
146
- Given test.png file content as request body
147
- When I do PUT request http://localhost:3100/thumbnails/crop,16,16,png
148
- Then response status should be 200
149
- And X-Input-Image-Mime-Type header should be image/png
150
-
151
- @hint @input
152
- Scenario: Hint on input image size
153
- Given test-large.jpg file content as request body
154
- When I do PUT request http://localhost:3100/thumbnails/crop,16,16,png
155
- Then response status should be 200
156
- And X-Input-Image-Width header should be 9911
157
- And X-Input-Image-Height header should be 14000
158
-