httpthumbnailer 0.1.0 → 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/VERSION +1 -1
- data/bin/httpthumbnailer +1 -2
- data/features/httpthumbnailer.feature +24 -0
- data/httpthumbnailer.gemspec +2 -2
- data/lib/httpthumbnailer/thumbnail_specs.rb +8 -0
- data/lib/httpthumbnailer/thumbnailer.rb +10 -10
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/httpthumbnailer
CHANGED
@@ -95,8 +95,7 @@ sinatra.put %r{^/thumbnail/(.*)} do |specs|
|
|
95
95
|
|
96
96
|
opts = {}
|
97
97
|
if settings.optimization
|
98
|
-
|
99
|
-
opts.merge!({'max-width' => biggest_spec.width, 'max-height' => biggest_spec.height})
|
98
|
+
opts.merge!({'max-width' => thumbnail_specs.max_width, 'max-height' => thumbnail_specs.max_height})
|
100
99
|
end
|
101
100
|
|
102
101
|
input_image_handler = $thumbnailer.load(request.body, opts)
|
@@ -39,6 +39,30 @@ Feature: Generating set of thumbnails with single PUT request
|
|
39
39
|
And that image pixel at 32x32 will be of color white
|
40
40
|
And there will be no leaked images
|
41
41
|
|
42
|
+
Scenario: Thumbnails of format INPUT should have same format as input image - for JPEG
|
43
|
+
Given test.jpg file content as request body
|
44
|
+
When I do PUT request http://localhost:3100/thumbnail/crop,16,16,PNG/crop,4,8,INPUT/crop,16,32,INPUT
|
45
|
+
Then response status will be 200
|
46
|
+
And I will get multipart response
|
47
|
+
Then first part will contain PNG image of size 16x16
|
48
|
+
And first part mime type will be image/png
|
49
|
+
Then second part will contain JPEG image of size 4x8
|
50
|
+
And second part mime type will be image/jpeg
|
51
|
+
Then third part will contain JPEG image of size 16x32
|
52
|
+
And third part mime type will be image/jpeg
|
53
|
+
|
54
|
+
Scenario: Thumbnails of format INPUT should have same format as input image - for PNG
|
55
|
+
Given test.png file content as request body
|
56
|
+
When I do PUT request http://localhost:3100/thumbnail/crop,16,16,JPEG/crop,4,8,INPUT/crop,16,32,INPUT
|
57
|
+
Then response status will be 200
|
58
|
+
And I will get multipart response
|
59
|
+
Then first part will contain JPEG image of size 16x16
|
60
|
+
And first part mime type will be image/jpeg
|
61
|
+
Then second part will contain PNG image of size 4x8
|
62
|
+
And second part mime type will be image/png
|
63
|
+
Then third part will contain PNG image of size 16x32
|
64
|
+
And third part mime type will be image/png
|
65
|
+
|
42
66
|
Scenario: Fit thumbnailing method
|
43
67
|
Given test.jpg file content as request body
|
44
68
|
When I do PUT request http://localhost:3100/thumbnail/fit,128,128,PNG
|
data/httpthumbnailer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "httpthumbnailer"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jakub Pastuszek"]
|
12
|
-
s.date = "2012-01-
|
12
|
+
s.date = "2012-01-12"
|
13
13
|
s.description = "Provides HTTP API for thumbnailing images"
|
14
14
|
s.email = "jpastuszek@gmail.com"
|
15
15
|
s.executables = ["httpthumbnailer"]
|
@@ -134,7 +134,7 @@ class Thumbnailer
|
|
134
134
|
ImageHandler.new do
|
135
135
|
process_image(@image, spec).render_on_background!((spec.options['background-color'] or 'white').sub(/^0x/, '#'))
|
136
136
|
end.use do |image|
|
137
|
-
yield Thumbnail.new(image, spec)
|
137
|
+
yield Thumbnail.new(image, spec.format == 'INPUT' ? @image.format : spec.format, spec.options['quality'])
|
138
138
|
end
|
139
139
|
rescue Magick::ImageMagickError => e
|
140
140
|
raise ImageTooLargeError, e if e.message =~ /cache resources exhausted/
|
@@ -174,18 +174,18 @@ class Thumbnailer
|
|
174
174
|
end
|
175
175
|
|
176
176
|
class Thumbnail
|
177
|
-
def initialize(image,
|
177
|
+
def initialize(image, format, quality = nil)
|
178
178
|
@image = image
|
179
|
-
@
|
179
|
+
@format = format
|
180
|
+
@quality = (quality or default_quality(format))
|
181
|
+
@quality &&= @quality.to_i
|
180
182
|
end
|
181
183
|
|
182
184
|
def data
|
183
|
-
|
184
|
-
quality = quality
|
185
|
-
|
186
|
-
spec = @spec
|
185
|
+
format = @format
|
186
|
+
quality = @quality
|
187
187
|
@image.to_blob do
|
188
|
-
self.format =
|
188
|
+
self.format = format
|
189
189
|
self.quality = quality if quality
|
190
190
|
end
|
191
191
|
end
|
@@ -193,9 +193,9 @@ class Thumbnailer
|
|
193
193
|
def mime_type
|
194
194
|
#@image.mime_type cannot be used since it is raw loaded image
|
195
195
|
#TODO: how do I do it better?
|
196
|
-
mime = case @
|
196
|
+
mime = case @format
|
197
197
|
when 'JPG' then 'jpeg'
|
198
|
-
else @
|
198
|
+
else @format.downcase
|
199
199
|
end
|
200
200
|
"image/#{mime}"
|
201
201
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpthumbnailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jakub Pastuszek
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-01-
|
18
|
+
date: 2012-01-12 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
type: :runtime
|