fastimage 1.6.3 → 1.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.textile +5 -3
- data/lib/fastimage.rb +16 -3
- data/test/fixtures/man.ico +0 -0
- data/test/fixtures/test.cur +0 -0
- data/test/fixtures/test2.bmp +0 -0
- data/test/test.rb +20 -5
- metadata +5 -3
- data/test/fixtures/test.ico +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c3ac7db254b241861f6b263dec85059a91802a6
|
4
|
+
data.tar.gz: 12ab9b17386c9d8cc62dff0924e273f3bd5da81c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0593a2af86dc99f70711b94a8950d0e58716dc7849592dfcd54be3cd19fff5f9d217961db54b774b33d6ec5241ff0789896f2130b474a74736b2d6def43825d
|
7
|
+
data.tar.gz: c813c61137248cf2005c406c1ce9d0d3e860929b4dd3c6ecc80bba2dbe4d010dbb14d939e5e049269c35ed6d6ebb0d451107e0b1022a048762fe02f5dcb86be4
|
data/README.textile
CHANGED
@@ -10,9 +10,9 @@ Your app needs to find the size or type of an image. This could be for adding w
|
|
10
10
|
|
11
11
|
But the image is not locally stored - it's on another asset server, or in the cloud - at Amazon S3 for example.
|
12
12
|
|
13
|
-
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 common image types (GIF, PNG, BMP), 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 much of the image to find the size.
|
13
|
+
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 common image types (GIF, PNG, BMP etc.), 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 much of the image to find the size.
|
14
14
|
|
15
|
-
FastImage does this minimal fetch for image types GIF, JPEG, PNG, TIFF, BMP and PSD. And it doesn't rely on installing external libraries such as RMagick (which relies on ImageMagick or GraphicsMagick) or ImageScience (which relies on FreeImage).
|
15
|
+
FastImage does this minimal fetch for image types GIF, JPEG, PNG, TIFF, BMP, ICO, CUR and PSD. And it doesn't rely on installing external libraries such as RMagick (which relies on ImageMagick or GraphicsMagick) or ImageScience (which relies on FreeImage).
|
16
16
|
|
17
17
|
You only need supply the uri, and FastImage will do the rest.
|
18
18
|
|
@@ -98,7 +98,7 @@ irb> puts Benchmark.measure {p FastImage.size(uri)}
|
|
98
98
|
|
99
99
|
h2. Tests
|
100
100
|
|
101
|
-
You'll need to @gem install fakeweb@ to be able to run the tests.
|
101
|
+
You'll need to @gem install fakeweb@ and possibly also @gem install test-unit@ to be able to run the tests.
|
102
102
|
|
103
103
|
bc.. $ ruby test.rb
|
104
104
|
Run options:
|
@@ -130,3 +130,5 @@ Pull requests and suggestions are always welcome. Thanks to all the contributors
|
|
130
130
|
* @benjaminjackson
|
131
131
|
* @muffinista
|
132
132
|
* @marcandre
|
133
|
+
* @apanzerj
|
134
|
+
|
data/lib/fastimage.rb
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
# No external libraries such as ImageMagick are used here, this is a very lightweight solution to
|
9
9
|
# finding image information.
|
10
10
|
#
|
11
|
-
# FastImage knows about GIF, JPEG, BMP, TIFF, PNG and PSD files.
|
11
|
+
# FastImage knows about GIF, JPEG, BMP, TIFF, ICO, CUR, PNG and PSD files.
|
12
12
|
#
|
13
13
|
# FastImage can also read files from the local filesystem by supplying the path instead of a uri.
|
14
14
|
# In this case FastImage uses the Addressable library to read the file in chunks of 256 bytes until
|
@@ -77,7 +77,7 @@ class FastImage
|
|
77
77
|
# If you wish FastImage to raise if it cannot size the image for any reason, then pass
|
78
78
|
# :raise_on_failure => true in the options.
|
79
79
|
#
|
80
|
-
# FastImage knows about GIF, JPEG, BMP, TIFF, PNG and
|
80
|
+
# FastImage knows about GIF, JPEG, BMP, TIFF, PNG, PSD, ICO and CUR files.
|
81
81
|
#
|
82
82
|
# === Example
|
83
83
|
#
|
@@ -98,6 +98,8 @@ class FastImage
|
|
98
98
|
# FastImage.size("http://pennysmalls.com/does_not_exist", :raise_on_failure=>true)
|
99
99
|
# => raises FastImage::ImageFetchFailure
|
100
100
|
# FastImage.size("http://stephensykes.com/favicon.ico", :raise_on_failure=>true)
|
101
|
+
# => [16, 16]
|
102
|
+
# FastImage.size("http://stephensykes.com/images/squareBlue.icns", :raise_on_failure=>true)
|
101
103
|
# => raises FastImage::UnknownImageType
|
102
104
|
# FastImage.size("http://stephensykes.com/favicon.ico", :raise_on_failure=>true, :timeout=>0.01)
|
103
105
|
# => raises FastImage::ImageFetchFailure
|
@@ -137,7 +139,7 @@ class FastImage
|
|
137
139
|
# => :bmp
|
138
140
|
# FastImage.type("test/fixtures/test.jpg")
|
139
141
|
# => :jpeg
|
140
|
-
# FastImage.type("http://
|
142
|
+
# FastImage.type("http://stephensykes.com/does_not_exist")
|
141
143
|
# => nil
|
142
144
|
# File.open("/some/local/file.gif", "r") {|io| FastImage.type(io)}
|
143
145
|
# => :gif
|
@@ -377,11 +379,22 @@ class FastImage
|
|
377
379
|
:tiff
|
378
380
|
when '8B'
|
379
381
|
:psd
|
382
|
+
when "\0\0"
|
383
|
+
# ico has either a 1 (for ico format) or 2 (for cursor) at offset 3
|
384
|
+
case @stream.peek(3).bytes.to_a.last
|
385
|
+
when 1 then :ico
|
386
|
+
when 2 then :cur
|
387
|
+
end
|
380
388
|
else
|
381
389
|
raise UnknownImageType
|
382
390
|
end
|
383
391
|
end
|
384
392
|
|
393
|
+
def parse_size_for_ico
|
394
|
+
@stream.read(8)[6..7].unpack('CC').map{|byte| byte == 0 ? 256 : byte }
|
395
|
+
end
|
396
|
+
alias_method :parse_size_for_cur, :parse_size_for_ico
|
397
|
+
|
385
398
|
def parse_size_for_gif
|
386
399
|
@stream.read(11)[6..10].unpack('SS')
|
387
400
|
end
|
Binary file
|
Binary file
|
Binary file
|
data/test/test.rb
CHANGED
@@ -24,13 +24,19 @@ GoodFixtures = {
|
|
24
24
|
"test.psd"=>[:psd, [17, 32]],
|
25
25
|
"exif_orientation.jpg"=>[:jpeg, [600, 450]],
|
26
26
|
"infinite.jpg"=>[:jpeg, [160,240]],
|
27
|
-
"orient_2.jpg"=>[:jpeg, [230,408]]
|
27
|
+
"orient_2.jpg"=>[:jpeg, [230,408]],
|
28
|
+
"favicon.ico" => [:ico, [16, 16]],
|
29
|
+
"man.ico" => [:ico, [48, 48]],
|
30
|
+
"test.cur" => [:cur, [32, 32]]
|
28
31
|
}
|
29
32
|
|
30
33
|
BadFixtures = [
|
31
34
|
"faulty.jpg",
|
32
|
-
"
|
35
|
+
"test_rgb.ct"
|
33
36
|
]
|
37
|
+
# man.ico courtesy of http://www.iconseeker.com/search-icon/artists-valley-sample/business-man-blue.html
|
38
|
+
# test_rgb.ct courtesy of http://fileformats.archiveteam.org/wiki/Scitex_CT
|
39
|
+
# test.cur courtesy of http://mimidestino.deviantart.com/art/Clash-Of-Clans-Dragon-Cursor-s-Punteros-489070897
|
34
40
|
|
35
41
|
TestUrl = "http://example.nowhere/"
|
36
42
|
|
@@ -74,7 +80,7 @@ class FastImageTest < Test::Unit::TestCase
|
|
74
80
|
end
|
75
81
|
|
76
82
|
def test_should_return_nil_when_image_type_not_known
|
77
|
-
assert_nil FastImage.size(TestUrl + "
|
83
|
+
assert_nil FastImage.size(TestUrl + "test_rgb.ct")
|
78
84
|
end
|
79
85
|
|
80
86
|
def test_should_return_nil_if_timeout_occurs
|
@@ -101,7 +107,7 @@ class FastImageTest < Test::Unit::TestCase
|
|
101
107
|
|
102
108
|
def test_should_raise_when_asked_when_image_type_not_known
|
103
109
|
assert_raises(FastImage::UnknownImageType) do
|
104
|
-
FastImage.size(TestUrl + "
|
110
|
+
FastImage.size(TestUrl + "test_rgb.ct", :raise_on_failure=>true)
|
105
111
|
end
|
106
112
|
end
|
107
113
|
|
@@ -157,7 +163,7 @@ class FastImageTest < Test::Unit::TestCase
|
|
157
163
|
end
|
158
164
|
|
159
165
|
def test_should_return_nil_when_image_type_not_known_for_local_file
|
160
|
-
assert_nil FastImage.size(File.join(FixturePath, "
|
166
|
+
assert_nil FastImage.size(File.join(FixturePath, "test_rgb.ct"))
|
161
167
|
end
|
162
168
|
|
163
169
|
def test_should_raise_when_asked_to_when_size_cannot_be_found_for_local_file
|
@@ -243,4 +249,13 @@ class FastImageTest < Test::Unit::TestCase
|
|
243
249
|
path = Pathname.new(File.join(FixturePath, "bad.jpg"))
|
244
250
|
assert_equal([500,500], FastImage.size(path))
|
245
251
|
end
|
252
|
+
|
253
|
+
def test_should_report_type_and_size_correctly_for_stringios
|
254
|
+
GoodFixtures.each do |fn, info|
|
255
|
+
string = File.read(File.join(FixturePath, fn))
|
256
|
+
stringio = StringIO.new(string)
|
257
|
+
assert_equal info[0], FastImage.type(stringio)
|
258
|
+
assert_equal info[1], FastImage.size(stringio)
|
259
|
+
end
|
260
|
+
end
|
246
261
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastimage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Sykes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -89,14 +89,16 @@ files:
|
|
89
89
|
- test/fixtures/faulty.jpg
|
90
90
|
- test/fixtures/folder with spaces/test.bmp
|
91
91
|
- test/fixtures/infinite.jpg
|
92
|
+
- test/fixtures/man.ico
|
92
93
|
- test/fixtures/orient_2.jpg
|
93
94
|
- test/fixtures/test.bmp
|
95
|
+
- test/fixtures/test.cur
|
94
96
|
- test/fixtures/test.gif
|
95
|
-
- test/fixtures/test.ico
|
96
97
|
- test/fixtures/test.jpg
|
97
98
|
- test/fixtures/test.png
|
98
99
|
- test/fixtures/test.psd
|
99
100
|
- test/fixtures/test.tiff
|
101
|
+
- test/fixtures/test2.bmp
|
100
102
|
- test/fixtures/test2.jpg
|
101
103
|
- test/fixtures/test2.tiff
|
102
104
|
- test/fixtures/test3.jpg
|
data/test/fixtures/test.ico
DELETED
Binary file
|