fastimage 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.textile +29 -33
  4. data/lib/fastimage.rb +7 -6
  5. metadata +8 -11
  6. data/README +0 -79
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41430d6372593b80ee08688d0d5ba73e6b75afe7
4
+ data.tar.gz: 6c087874cf7dc4fbc330bdc57b07d7e2a8adec2c
5
+ SHA512:
6
+ metadata.gz: 8c8a4315619a334e8de54d5162a7a96a1de1aadb272b7ad1bdb530559a4f465d4f821680c2ff06e9650c1f5b7130a803c0549a45086b9f6ef4d468269493b558
7
+ data.tar.gz: ad654e975fd54b5f7d3fd583d4d03bbae3d3b143622f292aa859f43c18d3d89279274bce3a271e2339da43b42a66c775557b4a6b4b3278c1bdd6f5e36f31d128
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2011 Stephen Sykes
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -14,17 +14,24 @@ FastImage does this minimal fetch for image types GIF, JPEG, PNG and BMP. And i
14
14
 
15
15
  You only need supply the uri, and FastImage will do the rest.
16
16
 
17
+ h2. Features
18
+
17
19
  Fastimage can also read local (and other) files, and uses the open-uri library to do so.
18
20
 
19
- And new in v1.2.9, FastImage will automatically read from any object that responds to :read - for
21
+ FastImage will automatically read from any object that responds to :read - for
20
22
  instance an IO object if that is passed instead of a URI.
21
23
 
22
- New in v1.2.10 FastImage will follow up to 4 HTTP redirects to get the image.
24
+ FastImage will follow up to 4 HTTP redirects to get the image.
25
+
26
+ FastImage will obey the http_proxy setting in your environment to route requests via a proxy.
27
+
28
+ You can add a timeout to the request which will limit the request time by passing :timeout => number_of_seconds.
29
+
30
+ FastImage normally replies will nil if it encounters an error, but you can pass :raise_on_failure => true to get an exception.
23
31
 
24
32
  h2. Examples
25
33
 
26
- <pre>
27
- <code>
34
+ <pre lang="ruby"><code>
28
35
  require 'fastimage'
29
36
 
30
37
  FastImage.size("http://stephensykes.com/images/ss.com_x.gif")
@@ -33,62 +40,51 @@ FastImage.type("http://stephensykes.com/images/pngimage")
33
40
  => :png
34
41
  FastImage.type("/some/local/file.gif")
35
42
  => :gif
36
- </code>
37
- </pre>
43
+ FastImage.size("http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg", :raise_on_failure=>true, :timeout=>0.1)
44
+ => FastImage::ImageFetchFailure: FastImage::ImageFetchFailure
45
+ FastImage.size("http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg", :raise_on_failure=>true, :timeout=>2.0)
46
+ => [9545, 6623]
47
+ </code></pre>
38
48
 
39
49
  h2. Installation
40
50
 
41
51
  h4. Gem
42
52
 
43
- <pre>
44
- <code>
45
- gem install fastimage
46
- </code>
47
- </pre>
53
+ bc. gem install fastimage
48
54
 
49
55
  h4. Rails
50
56
 
51
57
  Install the gem as above, and add it to your Gemfile if you are using bundler, or configure it in your environment.rb file as below:
52
- <pre>
53
- <code>
54
- ...
58
+ <pre lang="ruby"><code>
55
59
  Rails::Initializer.run do |config|
56
- ...
57
60
  config.gem "fastimage"
58
- ...
59
61
  end
60
- ...
61
- </code>
62
- </pre>
63
- Then you're off - just use FastImage.size() and FastImage.type() in your code as in the examples.
62
+ </code></pre>
63
+ Then you're off - just use @FastImage.size()@ and @FastImage.type()@ in your code as in the examples.
64
64
 
65
65
  h2. Documentation
66
66
 
67
- "http://rdoc.info/projects/sdsykes/fastimage":http://rdoc.info/projects/sdsykes/fastimage
67
+ "http://sdsykes.github.io/fastimage/rdoc/FastImage.html":http://sdsykes.github.io/fastimage/rdoc/FastImage.html
68
68
 
69
69
  h2. Tests
70
70
 
71
- You'll need to 'sudo gem install fakeweb' to be able to run the tests.
71
+ You'll need to @gem install fakeweb@ to be able to run the tests.
72
72
 
73
- <pre>
74
- <code>
75
- ruby test/test.rb
73
+ bc.. ruby ./test/test.rb
76
74
  Loaded suite test/test
77
75
  Started
78
76
  ...............
79
77
  Finished in 0.059392 seconds.
80
78
 
81
79
  15 tests, 27 assertions, 0 failures, 0 errors
82
- </code>
83
- </pre>
84
-
85
80
 
86
81
  h2. References
87
- * "http://pennysmalls.com/find-jpeg-dimensions-fast-in-pure-ruby-no-ima":http://pennysmalls.com/find-jpeg-dimensions-fast-in-pure-ruby-no-ima
88
- * "http://snippets.dzone.com/posts/show/805":http://snippets.dzone.com/posts/show/805
89
- * "http://www.anttikupila.com/flash/getting-jpg-dimensions-with-as3-without-loading-the-entire-file/":http://www.anttikupila.com/flash/getting-jpg-dimensions-with-as3-without-loading-the-entire-file/
90
- * "http://imagesize.rubyforge.org/":http://imagesize.rubyforge.org/
82
+
83
+ * "Pennysmalls - Find jpeg dimensions fast in pure Ruby, no image library needed":http://pennysmalls.wordpress.com/2008/08/19/find-jpeg-dimensions-fast-in-pure-ruby-no-ima/
84
+ * "DZone - Determine Image Size":http://snippets.dzone.com/posts/show/805
85
+ * "Antti Kupila - Getting JPG dimensions with AS3 without loading the entire file":http://www.anttikupila.com/flash/getting-jpg-dimensions-with-as3-without-loading-the-entire-file/
86
+ * "imagesize gem documentation":http://imagesize.rubyforge.org/
91
87
 
92
88
  h2. Licence
93
89
 
94
- MIT, see file MIT_LICENCE
90
+ MIT, see file "MIT-LICENSE":MIT-LICENSE
@@ -35,7 +35,7 @@
35
35
  # === References
36
36
  # * http://snippets.dzone.com/posts/show/805
37
37
  # * http://www.anttikupila.com/flash/getting-jpg-dimensions-with-as3-without-loading-the-entire-file/
38
- # * http://pennysmalls.com/find-jpeg-dimensions-fast-in-pure-ruby-no-ima
38
+ # * http://pennysmalls.wordpress.com/2008/08/19/find-jpeg-dimensions-fast-in-pure-ruby-no-ima/
39
39
  # * http://imagesize.rubyforge.org/
40
40
  #
41
41
 
@@ -184,7 +184,7 @@ class FastImage
184
184
 
185
185
  def fetch_using_http_from_parsed_uri
186
186
  setup_http
187
- @http.request_get(@parsed_uri.request_uri) do |res|
187
+ @http.request_get(@parsed_uri.request_uri, 'Accept-Encoding' => 'identity') do |res|
188
188
  if res.is_a?(Net::HTTPRedirection) && @redirect_count < 4
189
189
  @redirect_count += 1
190
190
  begin
@@ -246,6 +246,7 @@ class FastImage
246
246
  #
247
247
  def parse_packet(str)
248
248
  @str = (@unused_str || "") + str
249
+ @str.force_encoding("ASCII-8BIT") if has_encoding?
249
250
  @strpos = 0
250
251
  begin
251
252
  result = send("parse_#{@property}")
@@ -325,12 +326,12 @@ class FastImage
325
326
  when :started
326
327
  get_byte == 0xFF ? :sof : :started
327
328
  when :sof
328
- c = get_byte
329
- if (0xe0..0xef).include?(c)
329
+ case get_byte
330
+ when 0xe0..0xef
330
331
  :skipframe
331
- elsif [0xC0..0xC3, 0xC5..0xC7, 0xC9..0xCB, 0xCD..0xCF].detect {|r| r.include? c}
332
+ when 0xC0..0xC3, 0xC5..0xC7, 0xC9..0xCB, 0xCD..0xCF
332
333
  :readsize
333
- elsif c == 0xFF
334
+ when 0xFF
334
335
  :sof
335
336
  else
336
337
  :skipframe
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastimage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
5
- prerelease:
4
+ version: 1.3.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Stephen Sykes
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-19 00:00:00.000000000 Z
11
+ date: 2013-05-08 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: FastImage finds the size or type of an image given its uri by fetching
15
14
  as little as needed.
@@ -17,10 +16,9 @@ email: sdsykes@gmail.com
17
16
  executables: []
18
17
  extensions: []
19
18
  extra_rdoc_files:
20
- - README
21
19
  - README.textile
22
20
  files:
23
- - README
21
+ - MIT-LICENSE
24
22
  - README.textile
25
23
  - lib/fastimage.rb
26
24
  - test/fixtures/faulty.jpg
@@ -35,28 +33,27 @@ files:
35
33
  - test/test.rb
36
34
  homepage: http://github.com/sdsykes/fastimage
37
35
  licenses: []
36
+ metadata: {}
38
37
  post_install_message:
39
38
  rdoc_options:
40
39
  - --charset=UTF-8
41
40
  require_paths:
42
41
  - lib
43
42
  required_ruby_version: !ruby/object:Gem::Requirement
44
- none: false
45
43
  requirements:
46
- - - ! '>='
44
+ - - '>='
47
45
  - !ruby/object:Gem::Version
48
46
  version: '0'
49
47
  required_rubygems_version: !ruby/object:Gem::Requirement
50
- none: false
51
48
  requirements:
52
- - - ! '>='
49
+ - - '>='
53
50
  - !ruby/object:Gem::Version
54
51
  version: '0'
55
52
  requirements: []
56
53
  rubyforge_project:
57
- rubygems_version: 1.8.23
54
+ rubygems_version: 2.0.0
58
55
  signing_key:
59
- specification_version: 3
56
+ specification_version: 4
60
57
  summary: FastImage - Image info fast
61
58
  test_files:
62
59
  - test/test.rb
data/README DELETED
@@ -1,79 +0,0 @@
1
- FastImage
2
-
3
- FastImage finds the size or type of an image given its uri by fetching as little as needed
4
-
5
- The problem
6
-
7
- Your app needs to find the size or type of an image. This could be for adding width and height attributes to an image tag, for adjusting layouts or overlays to fit an image or any other of dozens of reasons.
8
-
9
- But the image is not locally stored - it's on another asset server, or in the cloud - at Amazon S3 for example.
10
-
11
- You don't want to download the entire image to your app server - it could be many tens of kilobytes, or even megabytes just to get this information. For most image types, the size of the image is simply stored at the start of the file. For JPEG files it's a little bit more complex, but even so you do not need to fetch most of the image to find the size.
12
-
13
- FastImage does this minimal fetch for image types GIF, JPEG, PNG and BMP. And it doesn't rely on installing external libraries such as RMagick (which relies on ImageMagick or GraphicsMagick) or ImageScience (which relies on FreeImage).
14
-
15
- You only need supply the uri, and FastImage will do the rest.
16
-
17
- Fastimage can also read local (and other) files, and uses the open-uri library to do so.
18
-
19
- And new in v1.2.9, FastImage will automatically read from any object that responds to :read - for
20
- instance an IO object if that is passed instead of a URI.
21
-
22
- New in v1.2.10 FastImage will follow up to 4 HTTP redirects to get the image.
23
-
24
- Examples
25
-
26
- require 'fastimage'
27
-
28
- FastImage.size("http://stephensykes.com/images/ss.com_x.gif")
29
- => [266, 56] # width, height
30
- FastImage.type("http://stephensykes.com/images/pngimage")
31
- => :png
32
- FastImage.type("/some/local/file.gif")
33
- => :gif
34
-
35
- Installation
36
-
37
- h4. Gem
38
-
39
- gem install fastimage
40
-
41
- h4. Rails
42
-
43
- Install the gem as above, and configure it in your environment.rb file as below:
44
-
45
- ...
46
- Rails::Initializer.run do |config|
47
- ...
48
- config.gem "fastimage", :lib=>"fastimage"
49
- ...
50
- end
51
- ...
52
-
53
- Then you're off - just use FastImage.size() and FastImage.type() in your code as in the examples.
54
-
55
- Documentation
56
-
57
- "http://rdoc.info/projects/sdsykes/fastimage":http://rdoc.info/projects/sdsykes/fastimage
58
-
59
- Tests
60
-
61
- You'll need to 'sudo gem install fakeweb' to be able to run the tests.
62
-
63
- ruby test/test.rb
64
- Loaded suite test/test
65
- Started
66
- ...............
67
- Finished in 0.059392 seconds.
68
-
69
- 15 tests, 27 assertions, 0 failures, 0 errors
70
-
71
-
72
- References
73
- * "http://pennysmalls.com/find-jpeg-dimensions-fast-in-pure-ruby-no-ima":http://pennysmalls.com/find-jpeg-dimensions-fast-in-pure-ruby-no-ima
74
- * "http://snippets.dzone.com/posts/show/805":http://snippets.dzone.com/posts/show/805
75
- * "http://www.anttikupila.com/flash/getting-jpg-dimensions-with-as3-without-loading-the-entire-file/":http://www.anttikupila.com/flash/getting-jpg-dimensions-with-as3-without-loading-the-entire-file/
76
- * "http://imagesize.rubyforge.org/":http://imagesize.rubyforge.org/
77
-
78
-
79
- (c) 2009 Stephen Sykes