scale_down 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ == 2012-01-24 ==
2
+ Version 0.6.1
3
+ Minor change in CMYK conversion
4
+
1
5
  == 2011-12-09 ==
2
6
  Version 0.6.0
3
7
  public_path is renamed public_folder
data/README.md ADDED
@@ -0,0 +1,148 @@
1
+ [![Build Status](https://secure.travis-ci.org/jweir/ScaleDown.png)](http://travis-ci.org/jweir/ScaleDown)
2
+
3
+ ScaleDown
4
+ ==========
5
+
6
+ An on demand image scaling server.
7
+
8
+ Images are scaled based upon their URL. An HMAC signature is used to prevent unauthorized scaling of images.
9
+
10
+ Supports cropping images and converts CMYK to RGB.
11
+
12
+ URL Schema
13
+ ==========
14
+
15
+ Your file on `example.com` has a public path of `/images/john/picture.png`. You want it scaled to fit in a 400x400 pixel box. **ScaleDown** is running on the subdomain `images`.
16
+
17
+ The URL to your image would be:
18
+
19
+ http://images.example.com/images/john/scaled/400x400/picture.png?HMAC_SIGNATURE
20
+
21
+ The scaled file is saved in a public path identical to the request. Once an image is scaled your webserve can statically server the file.
22
+
23
+ The schema is
24
+
25
+ http://:host/:path_to_file/scaled/:geometry/:filename?:hmac_signature
26
+
27
+ :host the address running ScaleDown
28
+ :path_to_file the public path of the original file
29
+ `scaled` keyword
30
+ :geometry width x height and an optional `-crop`
31
+ :filename the filename of the original image to scale
32
+ :hmac_signature security measure to validate the request
33
+
34
+
35
+ Geometry & Cropping
36
+ ====================
37
+
38
+ To crop an image include the `-crop` option. The image will be scaled and cropped to fit the geometry.
39
+
40
+ http://images.example.com/images/scaled/400x300-crop/logo.png?A3SDACEDF
41
+
42
+ Using `auto` as a dimension will fit the image to the other dimension.
43
+
44
+ For example, to ensure an image is 300 pixels wide set the height to auto
45
+
46
+ http://images.example.com/images/scaled/300xauto/logo.png/?A3SDACEDF
47
+
48
+ There is a very simple `/info` function for getting image dimensions. It just returns a string with the WIDTHxHEIGHT.
49
+
50
+ http://images.example.com/images/logo.png/info
51
+
52
+
53
+ HMAC
54
+ ====
55
+
56
+ You don't want someone taking down your server with malicious URLs, so an HMAC signature is used. This ensures that your URL was generated by a trusted source.
57
+
58
+ HMAC requires a shared key between the application generating the URL and the ScaleDown server.
59
+
60
+ Sample Ruby URL Generator
61
+ -------------------------
62
+
63
+ ```ruby
64
+ require 'ruby-hmac'
65
+
66
+ def signed_image_url(absolute_path, filename, geometry)
67
+ shared_secret = "secret"
68
+ hmac = HMAC::SHA1.new(shared_secret).update([absolute_path, 'scaled', geometry, filename].join("/")).to_s[0...8]
69
+ "http://images.example.com#{[absolute_path, 'scaled', geometry, CGI.escape(filename)].join("/")}?#{hmac}"
70
+ end
71
+ ```
72
+
73
+ Sample Node.js URL Generator
74
+ ----------------------------
75
+
76
+ ```javascript
77
+ // Uses the Node.js crypot library
78
+ var crypto = require('crypto')
79
+
80
+ function hmac(string){
81
+ var shared_secret = "secret"
82
+ return crypto.createHmac('sha1',shared_secret).update(string).digest('hex').substr(0,8)
83
+ }
84
+
85
+ function signed_image_url(absolute_path, filename, geometry){
86
+ signature = hmac( [ absolute_path, '/scaled', "/" + geometry, "/", filename].join("") )
87
+ return [global.$FD.assetHost, absolute_path, '/scaled', "/", geometry, "/",escape(filename)].join("") + "?"+ signature
88
+ }
89
+ ```
90
+
91
+ PNG, JPG, TIFF and other images supported
92
+ ========================================
93
+
94
+ ScaleDown will handle any image that Image Magick can process. But there are some rules:
95
+
96
+ * PNGs remain PNGs
97
+ * All other images are converted to JPG and issued a 301 redirect
98
+
99
+ Installation & Configuration
100
+ ==============================
101
+
102
+ gem install scale_down
103
+
104
+ Create a Rackup file (config.ru). See https://github.com/jweir/ScaleDown/tree/master/config_sample.ru more options
105
+
106
+ ```ruby
107
+ require 'rubygems'
108
+ require 'scale_down'
109
+
110
+ ScaleDown.tap do |config|
111
+ # Shared secret for generating the HMAC signature
112
+ config.hmac_key = "secret"
113
+
114
+ # Path to the public directory
115
+ config.public_folder = File.expand_path(File.dirname(__FILE__))+"/public"
116
+ end
117
+
118
+ run ScaleDown::Controller
119
+ ```
120
+
121
+ Configure Nginx, Apache, etc to run the server.
122
+
123
+ Known Issues
124
+ ===========
125
+
126
+ Pluses in filenames will not route properly. Filenames need to have these removed or replaced.
127
+
128
+ Dependencies
129
+ ============
130
+
131
+ * Sinatra
132
+ * RMagick
133
+ * Ruby-HMAC
134
+
135
+ RMagick can be a bit tricky to install, these links http://www.google.com/search?q=install+rmagick might help.
136
+
137
+ LICENSE
138
+ =======
139
+
140
+ (The MIT License)
141
+
142
+ Copyright © 2011 John Weir & Fame Driver LLC
143
+
144
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
145
+
146
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
147
+
148
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -13,7 +13,6 @@ class ScaleDown::Image
13
13
  include Magick
14
14
 
15
15
  class << self
16
-
17
16
  def scale(properties)
18
17
  new(properties).valid?
19
18
  end
@@ -55,6 +54,7 @@ class ScaleDown::Image
55
54
  # file.destroy!
56
55
  end
57
56
  rescue Magick::ImageMagickError => e
57
+ # TODO include the error in the HTTP response
58
58
  end
59
59
  end
60
60
 
@@ -70,8 +70,11 @@ class ScaleDown::Image
70
70
 
71
71
  def fix_color_space(file)
72
72
  if file.colorspace == Magick::CMYKColorspace
73
+ file.strip!
73
74
  file.add_profile "#{File.expand_path(File.dirname(__FILE__))}/../../color_profiles/sRGB.icm"
74
- file.quantize 2**24, Magick::RGBColorspace
75
+ file.quantize(2**24, Magick::RGBColorspace).tap do |image|
76
+ image.colorspace = Magick::RGBColorspace
77
+ end
75
78
  else
76
79
  file
77
80
  end
@@ -1,3 +1,3 @@
1
1
  module ScaleDown
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
data/scale_down.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency "ruby-hmac", ">= 0.4.0"
20
20
 
21
21
  s.add_development_dependency "contest", ">= 0.1.2"
22
+ s.add_development_dependency "rake", ">= 0.9.2.2"
22
23
  s.add_development_dependency "mocha", "0.9.8"
23
24
  s.add_development_dependency "rack-test", "0.5.6"
24
25
 
@@ -146,8 +146,8 @@ class ScaleDown::Image::Test < Test::Unit::TestCase
146
146
  end
147
147
  end
148
148
 
149
- context "CMYK images" do
150
- should "be converted to RGB" do
149
+ context "CMYK" do
150
+ should "convert TIF's to RGB JPGs" do
151
151
  create \
152
152
  fixture_path("files/cmyk.tif"),
153
153
  fixture_path("scaled_test/scaled/graphic.jpg"),
@@ -157,13 +157,13 @@ class ScaleDown::Image::Test < Test::Unit::TestCase
157
157
  assert_equal Magick::RGBColorspace, image.colorspace
158
158
  end
159
159
 
160
- should "convert JPGs to RGB JPEGS" do
160
+ should "JPGs should covert to RGB JPGS" do
161
161
  create \
162
162
  fixture_path("files/cmyk_gray.jpg"),
163
- fixture_path("scaled_test/scaled/graphic_2.jpg"),
163
+ fixture_path("scaled_test/scaled/rgb.jpg"),
164
164
  { :width => "auto", :height => 200}
165
165
 
166
- image = Magick::Image.read(fixture_path("scaled_test/scaled/graphic_2.jpg")).first
166
+ image = Magick::Image.read(fixture_path("scaled_test/scaled/rgb.jpg")).first
167
167
  assert_equal Magick::RGBColorspace, image.colorspace
168
168
  end
169
169
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scale_down
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-13 00:00:00.000000000Z
12
+ date: 2012-01-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rmagick
16
- requirement: &2164341720 !ruby/object:Gem::Requirement
16
+ requirement: &2153706660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2164341720
24
+ version_requirements: *2153706660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sinatra
27
- requirement: &2164341220 !ruby/object:Gem::Requirement
27
+ requirement: &2153706160 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2164341220
35
+ version_requirements: *2153706160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ruby-hmac
38
- requirement: &2164340760 !ruby/object:Gem::Requirement
38
+ requirement: &2153705700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.4.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2164340760
46
+ version_requirements: *2153705700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: contest
49
- requirement: &2164340300 !ruby/object:Gem::Requirement
49
+ requirement: &2153705240 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,21 @@ dependencies:
54
54
  version: 0.1.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2164340300
57
+ version_requirements: *2153705240
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: &2153704780 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 0.9.2.2
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2153704780
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: mocha
60
- requirement: &2164370020 !ruby/object:Gem::Requirement
71
+ requirement: &2153734500 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - =
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: 0.9.8
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *2164370020
79
+ version_requirements: *2153734500
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: rack-test
71
- requirement: &2164369560 !ruby/object:Gem::Requirement
82
+ requirement: &2153734040 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - =
@@ -76,7 +87,7 @@ dependencies:
76
87
  version: 0.5.6
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *2164369560
90
+ version_requirements: *2153734040
80
91
  description: ''
81
92
  email:
82
93
  - john@famedriver.com
@@ -85,9 +96,10 @@ extensions: []
85
96
  extra_rdoc_files: []
86
97
  files:
87
98
  - .gitignore
99
+ - .travis.yml
88
100
  - CHANGES
89
101
  - Gemfile
90
- - README.rdoc
102
+ - README.md
91
103
  - Rakefile
92
104
  - color_profiles/sRGB.icm
93
105
  - config_sample.ru
data/README.rdoc DELETED
@@ -1,134 +0,0 @@
1
- = ScaleDown
2
-
3
- An on demand image scaling server.
4
-
5
- Images are scaled based upon their URL. An HMAC signature is used to prevent unauthorized scaling of images.
6
-
7
- Supports cropping images and converts CMYK to RGB.
8
-
9
- == The URL schema
10
-
11
- Your file on `example.com` has a public path of `/images/john/picture.png`. You want it scaled to fit in a 400x400 pixel box. *ScaleDown* is running on the subdomain `images`.
12
-
13
- The URL to your image would be:
14
-
15
- http://images.example.com/images/john/scaled/400x400/picture.png?HMAC_SIGNATURE
16
-
17
- The scaled file will be saved in a public path identical to the request. So once an image is scaled your webserver, Apache, Nginx, etc, can statically server the file.
18
-
19
- The schema is
20
-
21
- http://:host/:path_to_file/scaled/:geometry/:filename?:hmac_signature
22
-
23
- :host is the address running ScaleDown
24
-
25
- :path_to_file is the public path of the original file
26
-
27
- `scaled` keyword
28
-
29
- :geometry is width x height and an optional `-crop`
30
-
31
- :filename is the name of the image to scale
32
-
33
- :hmac_signature a security measure to validate the request
34
-
35
- == Geometry & Cropping
36
-
37
- To crop an image include the `-crop` option. The image will be scaled and cropped to fit the geometry.
38
-
39
- http://images.example.com/images/scaled/400x300-crop/logo.png?A3SDACEDF
40
-
41
- Using `auto` as a dimension will fit the image to other dimension.
42
-
43
- For example, to ensure an image is 300 pixels wide set the height to auto
44
-
45
- http://images.example.com/images/scaled/300xauto/logo.png/?A3SDACEDF
46
-
47
- There is a very simple `/info` function for getting image dimensions. It just returns a string with the WIDTHxHEIGHT.
48
-
49
- http://images.example.com/images/logo.png/info
50
-
51
- == HMAC
52
-
53
- You don't want someone taking down your server with malicious URLs, so an HMAC signature is used. This ensures that your URL was generated by a trusted source.
54
-
55
- HMAC requires a shared key between the application generating the URL and the ScaleDown server.
56
-
57
- === Sample Ruby URL Generator
58
-
59
- require 'ruby-hmac'
60
-
61
- def signed_image_url(absolute_path, filename, geometry)
62
- shared_secret = "secret"
63
- hmac = HMAC::SHA1.new(shared_secret).update([absolute_path, 'scaled', geometry, filename].join("/")).to_s[0...8]
64
- "http://images.example.com#{[absolute_path, 'scaled', geometry, CGI.escape(filename)].join("/")}?#{hmac}"
65
- end
66
-
67
- === Sample Node.js URL Generator
68
-
69
- // Uses the Node.js crypot library
70
- var crypto = require('crypto')
71
-
72
- function hmac(string){
73
- var shared_secret = "secret"
74
- return crypto.createHmac('sha1',shared_secret).update(string).digest('hex').substr(0,8)
75
- }
76
-
77
- function signed_image_url(absolute_path, filename, geometry){
78
- signature = hmac( [ absolute_path, '/scaled', "/" + geometry, "/", filename].join("") )
79
- return [global.$FD.assetHost, absolute_path, '/scaled', "/", geometry, "/",escape(filename)].join("") + "?"+ signature
80
- }
81
-
82
- == Images: PNGs, JPGs, Tiffs and others
83
-
84
- ScaleDown will handle any image that Image Magick can process. But there are some rules:
85
-
86
- * PNGs remain PNGs and JPGs remain JPGS
87
- * All other images are converted to JPG and issued a 301 redirect
88
-
89
- == Installation and Configuration
90
-
91
- gem install scale_down
92
-
93
- Create a Rackup file (config.ru). See https://github.com/jweir/ScaleDown/tree/master/config_sample.ru more options
94
-
95
- require 'rubygems'
96
- require 'scale_down'
97
-
98
- ScaleDown.tap do |config|
99
- # Shared secret for generating the HMAC signature
100
- config.hmac_key = "secret"
101
-
102
- # Path to the public directory
103
- config.public_folder = File.expand_path(File.dirname(__FILE__))+"/public"
104
- end
105
-
106
- run ScaleDown::Controller
107
-
108
- Configure Nginx, Apache, etc to run the server.
109
-
110
- == Known Issues
111
-
112
- Pluses in filenames will not route properly. Filenames need to have these removed or replaced.
113
-
114
- == Dependencies
115
-
116
- * Sinatra
117
- * RMagick
118
- * Ruby-HMAC
119
-
120
- RMagick can be a bit tricky to install, these links[http://www.google.com/search?q=install+rmagick] might help.
121
-
122
- == License
123
-
124
- LICENSE:
125
-
126
- (The MIT License)
127
-
128
- Copyright © 2011 John Weir & Fame Driver LLC
129
-
130
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
131
-
132
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
133
-
134
- THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.