sdsykes-fastimage 1.1.2 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +74 -0
- data/README.textile +5 -1
- data/VERSION.yml +2 -2
- data/lib/fastimage.rb +5 -5
- data/test/test.rb +1 -1
- metadata +6 -5
data/README
CHANGED
@@ -0,0 +1,74 @@
|
|
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
|
+
Examples
|
20
|
+
|
21
|
+
require 'fastimage'
|
22
|
+
|
23
|
+
FastImage.size("http://stephensykes.com/images/ss.com_x.gif")
|
24
|
+
=> [266, 56] # width, height
|
25
|
+
FastImage.type("http://stephensykes.com/images/pngimage")
|
26
|
+
=> :png
|
27
|
+
FastImage.type("/some/local/file.gif")
|
28
|
+
=> :gif
|
29
|
+
|
30
|
+
Installation
|
31
|
+
|
32
|
+
h4. Gem
|
33
|
+
|
34
|
+
sudo gem install sdsykes-fastimage -s http://gems.github.com
|
35
|
+
|
36
|
+
h4. Rails
|
37
|
+
|
38
|
+
Install the gem as above, and configure it in your environment.rb file as below:
|
39
|
+
|
40
|
+
...
|
41
|
+
Rails::Initializer.run do |config|
|
42
|
+
...
|
43
|
+
config.gem "sdsykes-fastimage", :lib=>"fastimage"
|
44
|
+
...
|
45
|
+
end
|
46
|
+
...
|
47
|
+
|
48
|
+
Then you're off - just use FastImage.size() and FastImage.type() in your code as in the examples.
|
49
|
+
|
50
|
+
Documentation
|
51
|
+
|
52
|
+
"http://rdoc.info/projects/sdsykes/fastimage":http://rdoc.info/projects/sdsykes/fastimage
|
53
|
+
|
54
|
+
Tests
|
55
|
+
|
56
|
+
You'll need to 'sudo gem install fakeweb' to be able to run the tests.
|
57
|
+
|
58
|
+
ruby test/test.rb
|
59
|
+
Loaded suite test/test
|
60
|
+
Started
|
61
|
+
...............
|
62
|
+
Finished in 0.059392 seconds.
|
63
|
+
|
64
|
+
15 tests, 27 assertions, 0 failures, 0 errors
|
65
|
+
|
66
|
+
|
67
|
+
References
|
68
|
+
* "http://pennysmalls.com/2008/08/19/find-jpeg-dimensions-fast-in-ruby/":http://pennysmalls.com/2008/08/19/find-jpeg-dimensions-fast-in-ruby/
|
69
|
+
* "http://snippets.dzone.com/posts/show/805":http://snippets.dzone.com/posts/show/805
|
70
|
+
* "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/
|
71
|
+
* "http://imagesize.rubyforge.org/":http://imagesize.rubyforge.org/
|
72
|
+
|
73
|
+
|
74
|
+
(c) 2009 Stephen Sykes
|
data/README.textile
CHANGED
@@ -35,7 +35,11 @@ h2. Installation
|
|
35
35
|
|
36
36
|
h4. Gem
|
37
37
|
|
38
|
+
<pre>
|
39
|
+
<code>
|
38
40
|
sudo gem install sdsykes-fastimage -s http://gems.github.com
|
41
|
+
</code>
|
42
|
+
</pre>
|
39
43
|
|
40
44
|
h4. Rails
|
41
45
|
|
@@ -45,7 +49,7 @@ Install the gem as above, and configure it in your environment.rb file as below:
|
|
45
49
|
...
|
46
50
|
Rails::Initializer.run do |config|
|
47
51
|
...
|
48
|
-
config.gem "fastimage"
|
52
|
+
config.gem "sdsykes-fastimage", :lib=>"fastimage"
|
49
53
|
...
|
50
54
|
end
|
51
55
|
...
|
data/VERSION.yml
CHANGED
data/lib/fastimage.rb
CHANGED
@@ -67,7 +67,7 @@ class FastImage
|
|
67
67
|
#
|
68
68
|
# FastImage.size("http://stephensykes.com/images/ss.com_x.gif")
|
69
69
|
# => [266, 56]
|
70
|
-
# FastImage.
|
70
|
+
# FastImage.size("http://stephensykes.com/images/pngimage")
|
71
71
|
# => [16, 16]
|
72
72
|
# FastImage.size("http://farm4.static.flickr.com/3023/3047236863_9dce98b836.jpg")
|
73
73
|
# => [500, 375]
|
@@ -114,11 +114,11 @@ class FastImage
|
|
114
114
|
# FastImage.type("http://stephensykes.com/images/pngimage")
|
115
115
|
# => :png
|
116
116
|
# FastImage.type("http://farm4.static.flickr.com/3023/3047236863_9dce98b836.jpg")
|
117
|
-
# => :
|
117
|
+
# => :jpeg
|
118
118
|
# FastImage.type("http://www-ece.rice.edu/~wakin/images/lena512.bmp")
|
119
119
|
# => :bmp
|
120
120
|
# FastImage.type("test/fixtures/test.jpg")
|
121
|
-
# => :
|
121
|
+
# => :jpeg
|
122
122
|
# FastImage.type("http://pennysmalls.com/does_not_exist")
|
123
123
|
# => nil
|
124
124
|
#
|
@@ -227,7 +227,7 @@ class FastImage
|
|
227
227
|
when "GI"
|
228
228
|
:gif
|
229
229
|
when 0xff.chr + 0xd8.chr
|
230
|
-
:
|
230
|
+
:jpeg
|
231
231
|
when 0x89.chr + "P"
|
232
232
|
:png
|
233
233
|
else
|
@@ -243,7 +243,7 @@ class FastImage
|
|
243
243
|
get_chars(23)[14..22].unpack('NN')
|
244
244
|
end
|
245
245
|
|
246
|
-
def
|
246
|
+
def parse_size_for_jpeg
|
247
247
|
loop do
|
248
248
|
@state = case @state
|
249
249
|
when nil
|
data/test/test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sdsykes-fastimage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Sykes
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-17 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -36,8 +36,9 @@ files:
|
|
36
36
|
- test/fixtures/test.jpg
|
37
37
|
- test/fixtures/test.png
|
38
38
|
- test/test.rb
|
39
|
-
has_rdoc:
|
39
|
+
has_rdoc: false
|
40
40
|
homepage: http://github.com/sdsykes/fastimage
|
41
|
+
licenses:
|
41
42
|
post_install_message:
|
42
43
|
rdoc_options:
|
43
44
|
- --inline-source
|
@@ -59,9 +60,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
60
|
requirements: []
|
60
61
|
|
61
62
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.
|
63
|
+
rubygems_version: 1.3.5
|
63
64
|
signing_key:
|
64
|
-
specification_version:
|
65
|
+
specification_version: 3
|
65
66
|
summary: FastImage - Image info fast
|
66
67
|
test_files: []
|
67
68
|
|