fastimage 1.6.6 → 1.6.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.textile +15 -4
- data/lib/fastimage.rb +53 -8
- data/test/fixtures/webp_vp8.webp +0 -0
- data/test/fixtures/webp_vp8l.webp +0 -0
- data/test/fixtures/webp_vp8x.webp +0 -0
- data/test/test.rb +15 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0cc039d623dc912c65fb475ac7fcf40e6908075
|
4
|
+
data.tar.gz: d0904edca54dbb88a60dcfc3e38405c7133efcdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70886f6c9b00ee5a47af1beb69fdccaa6d1611ee264eba196c5773e2b0f6959b7cec9dc60c1540851788190d2e64c763094be8cd9ff44d0ca0ab52ea7461f6d7
|
7
|
+
data.tar.gz: 14f89c0602a5d7602d28d1e2fad44c47009afb004f4635f44fc7131ad2b2a49df4c9062041799556e04297ac8c214afe15b3608284763d53282dd93294d4edcf
|
data/README.textile
CHANGED
@@ -12,15 +12,16 @@ But the image is not locally stored - it's on another asset server, or in the cl
|
|
12
12
|
|
13
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, ICO, CUR and
|
15
|
+
FastImage does this minimal fetch for image types GIF, JPEG, PNG, TIFF, BMP, ICO, CUR, PSD and WEBP. 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
|
|
19
19
|
h2. Features
|
20
20
|
|
21
|
-
Fastimage can also read local (and other) files
|
21
|
+
Fastimage can also read local (and other) files - anything that is not parseable as a URI will be
|
22
|
+
interpreted as a filename, and FastImage will attempt to open it with File#open.
|
22
23
|
|
23
|
-
FastImage will automatically read from any object that responds to :read - for
|
24
|
+
FastImage will also automatically read from any object that responds to :read - for
|
24
25
|
instance an IO object if that is passed instead of a URI.
|
25
26
|
|
26
27
|
FastImage will follow up to 4 HTTP redirects to get the image.
|
@@ -31,6 +32,10 @@ You can add a timeout to the request which will limit the request time by passin
|
|
31
32
|
|
32
33
|
FastImage normally replies will nil if it encounters an error, but you can pass :raise_on_failure => true to get an exception.
|
33
34
|
|
35
|
+
h2. Security
|
36
|
+
|
37
|
+
As of v1.6.7 FastImage no longer uses openuri to open files, but directly calls File.open. But take care to sanitise the strings passed to FastImage; it will try to read from whatever is passed.
|
38
|
+
|
34
39
|
h2. Examples
|
35
40
|
|
36
41
|
<pre lang="ruby"><code>
|
@@ -113,9 +118,15 @@ h2. References
|
|
113
118
|
* "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/
|
114
119
|
* "DZone - Determine Image Size":http://snippets.dzone.com/posts/show/805
|
115
120
|
* "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/
|
116
|
-
* "imagesize gem
|
121
|
+
* "imagesize gem":https://rubygems.org/gems/imagesize
|
117
122
|
* "EXIF Reader":https://github.com/remvee/exifr
|
118
123
|
|
124
|
+
h2. FastImage in other languages
|
125
|
+
|
126
|
+
* "Python by bmuller":https://github.com/bmuller/fastimage
|
127
|
+
* "Swift by kaishin":https://github.com/kaishin/ImageScout
|
128
|
+
* "Go by rubenfonseca":https://github.com/rubenfonseca/fastimage
|
129
|
+
|
119
130
|
h2. Licence
|
120
131
|
|
121
132
|
MIT, see file "MIT-LICENSE":MIT-LICENSE
|
data/lib/fastimage.rb
CHANGED
@@ -8,10 +8,10 @@
|
|
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, ICO, CUR, PNG and
|
11
|
+
# FastImage knows about GIF, JPEG, BMP, TIFF, ICO, CUR, PNG, PSD and WEBP files.
|
12
12
|
#
|
13
13
|
# FastImage can also read files from the local filesystem by supplying the path instead of a uri.
|
14
|
-
# In this case FastImage
|
14
|
+
# In this case FastImage reads the file in chunks of 256 bytes until
|
15
15
|
# it has enough. This is possibly a useful bandwidth-saving feature if the file is on a network
|
16
16
|
# attached disk rather than truly local.
|
17
17
|
#
|
@@ -36,7 +36,7 @@
|
|
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
38
|
# * http://pennysmalls.wordpress.com/2008/08/19/find-jpeg-dimensions-fast-in-pure-ruby-no-ima/
|
39
|
-
# *
|
39
|
+
# * https://rubygems.org/gems/imagesize
|
40
40
|
# * https://github.com/remvee/exifr
|
41
41
|
#
|
42
42
|
|
@@ -76,7 +76,7 @@ class FastImage
|
|
76
76
|
# If you wish FastImage to raise if it cannot size the image for any reason, then pass
|
77
77
|
# :raise_on_failure => true in the options.
|
78
78
|
#
|
79
|
-
# FastImage knows about GIF, JPEG, BMP, TIFF, PNG, PSD
|
79
|
+
# FastImage knows about GIF, JPEG, BMP, TIFF, ICO, CUR, PNG, PSD and WEBP files.
|
80
80
|
#
|
81
81
|
# === Example
|
82
82
|
#
|
@@ -168,12 +168,12 @@ class FastImage
|
|
168
168
|
begin
|
169
169
|
@parsed_uri = Addressable::URI.parse(uri)
|
170
170
|
rescue Addressable::URI::InvalidURIError
|
171
|
-
|
171
|
+
fetch_using_file_open
|
172
172
|
else
|
173
173
|
if @parsed_uri.scheme == "http" || @parsed_uri.scheme == "https"
|
174
174
|
fetch_using_http
|
175
175
|
else
|
176
|
-
|
176
|
+
fetch_using_file_open
|
177
177
|
end
|
178
178
|
end
|
179
179
|
end
|
@@ -304,8 +304,8 @@ class FastImage
|
|
304
304
|
parse_packets FiberStream.new(read_fiber)
|
305
305
|
end
|
306
306
|
|
307
|
-
def
|
308
|
-
open(@uri) do |s|
|
307
|
+
def fetch_using_file_open
|
308
|
+
File.open(@uri) do |s|
|
309
309
|
fetch_using_read(s)
|
310
310
|
end
|
311
311
|
end
|
@@ -399,6 +399,12 @@ class FastImage
|
|
399
399
|
when 1 then :ico
|
400
400
|
when 2 then :cur
|
401
401
|
end
|
402
|
+
when "RI"
|
403
|
+
if @stream.peek(12)[8..11] == "WEBP"
|
404
|
+
:webp
|
405
|
+
else
|
406
|
+
raise UnknownImageType
|
407
|
+
end
|
402
408
|
else
|
403
409
|
raise UnknownImageType
|
404
410
|
end
|
@@ -473,6 +479,45 @@ class FastImage
|
|
473
479
|
[result.first, result.last.abs]
|
474
480
|
end
|
475
481
|
|
482
|
+
def parse_size_for_webp
|
483
|
+
vp8 = @stream.read(16)[12..15]
|
484
|
+
len = @stream.read(4).unpack("V")
|
485
|
+
case vp8
|
486
|
+
when "VP8 "
|
487
|
+
parse_size_vp8
|
488
|
+
when "VP8L"
|
489
|
+
parse_size_vp8l
|
490
|
+
when "VP8X"
|
491
|
+
parse_size_vp8x
|
492
|
+
else
|
493
|
+
nil
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
def parse_size_vp8
|
498
|
+
w, h = @stream.read(10).unpack("@6vv")
|
499
|
+
[w & 0x3fff, h & 0x3fff]
|
500
|
+
end
|
501
|
+
|
502
|
+
def parse_size_vp8l
|
503
|
+
@stream.read(1) # 0x2f
|
504
|
+
b1, b2, b3, b4 = @stream.read(4).bytes.to_a
|
505
|
+
[1 + (((b2 & 0x3f) << 8) | b1), 1 + (((b4 & 0xF) << 10) | (b3 << 2) | ((b2 & 0xC0) >> 6))]
|
506
|
+
end
|
507
|
+
|
508
|
+
def parse_size_vp8x
|
509
|
+
flags = @stream.read(4).unpack("C")[0]
|
510
|
+
b1, b2, b3, b4, b5, b6 = @stream.read(6).unpack("CCCCCC")
|
511
|
+
width, height = 1 + b1 + (b2 << 8) + (b3 << 16), 1 + b4 + (b5 << 8) + (b6 << 16)
|
512
|
+
|
513
|
+
if flags & 8 > 0 # exif
|
514
|
+
# parse exif for orientation
|
515
|
+
# TODO: find or create test images for this
|
516
|
+
end
|
517
|
+
|
518
|
+
return [width, height]
|
519
|
+
end
|
520
|
+
|
476
521
|
class Exif # :nodoc:
|
477
522
|
attr_reader :width, :height
|
478
523
|
def initialize(stream)
|
Binary file
|
Binary file
|
Binary file
|
data/test/test.rb
CHANGED
@@ -27,7 +27,10 @@ GoodFixtures = {
|
|
27
27
|
"orient_2.jpg"=>[:jpeg, [230,408]],
|
28
28
|
"favicon.ico" => [:ico, [16, 16]],
|
29
29
|
"man.ico" => [:ico, [48, 48]],
|
30
|
-
"test.cur" => [:cur, [32, 32]]
|
30
|
+
"test.cur" => [:cur, [32, 32]],
|
31
|
+
"webp_vp8x.webp" => [:webp, [386, 395]],
|
32
|
+
"webp_vp8l.webp" => [:webp, [386, 395]],
|
33
|
+
"webp_vp8.webp" => [:webp, [550, 368]]
|
31
34
|
}
|
32
35
|
|
33
36
|
BadFixtures = [
|
@@ -276,4 +279,15 @@ class FastImageTest < Test::Unit::TestCase
|
|
276
279
|
FastImage.size(url, :raise_on_failure => true)
|
277
280
|
end
|
278
281
|
end
|
282
|
+
|
283
|
+
def test_cant_access_shell
|
284
|
+
url = "|echo>shell_test"
|
285
|
+
%x{rm -f shell_test}
|
286
|
+
FastImage.size(url)
|
287
|
+
assert_raises(Errno::ENOENT) do
|
288
|
+
File.open("shell_test")
|
289
|
+
end
|
290
|
+
ensure
|
291
|
+
%x{rm -f shell_test}
|
292
|
+
end
|
279
293
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Sykes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -105,6 +105,9 @@ files:
|
|
105
105
|
- test/fixtures/test3.jpg
|
106
106
|
- test/fixtures/test4.jpg
|
107
107
|
- test/fixtures/truncated_gzipped.jpg
|
108
|
+
- test/fixtures/webp_vp8.webp
|
109
|
+
- test/fixtures/webp_vp8l.webp
|
110
|
+
- test/fixtures/webp_vp8x.webp
|
108
111
|
- test/test.rb
|
109
112
|
homepage: http://github.com/sdsykes/fastimage
|
110
113
|
licenses:
|