image_info 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +3 -2
- data/lib/image_info/image.rb +1 -1
- data/lib/image_info/null_parser.rb +12 -0
- data/lib/image_info/parser.rb +11 -5
- data/lib/image_info/processor.rb +1 -0
- data/lib/image_info/request_handler.rb +8 -5
- data/lib/image_info/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e64be805d1d84727d771133650ff254e7b8cb66
|
4
|
+
data.tar.gz: 330145b1fb6c7fe6c5916de26dcac0a284240e31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4025152ff395c4a4abb50c1f8715fe80b9ac81ed0e02a8b987c010349241d9da2879927eaf29bc1b4b9efae0cceed58acab6a63754fffe4314b77687c451dc5c
|
7
|
+
data.tar.gz: 1576e24fa6630e7168be36b915e74b93575155a54a50dcc1d99cc33d7fd9cb8ef295d1e39e05e421e0da6477831e7944ff5021719b984fbd68bc4313341fdfcb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
* 1.1.1
|
2
|
+
|
3
|
+
Now only fetch partial image data to compute its size and type.
|
4
|
+
|
5
|
+
Thanks to [vdaubry](https://github.com/vdaubry) the gem now uses typhoeus
|
6
|
+
stream capability to fetch images and get its size and type, aborting the
|
7
|
+
request if necessary. Make sure to use typhoeus `v0.7.3` in order to benefit
|
8
|
+
from this update since there was an issue with previous typhoeus version when
|
9
|
+
aborting ongoing requests.
|
10
|
+
|
11
|
+
Fixes [#1](https://github.com/gottfrois/image_info/issues/1)
|
12
|
+
|
13
|
+
Also fix URL encoding issues.
|
14
|
+
|
1
15
|
* 1.1.0
|
2
16
|
|
3
17
|
- Introduces `width` and `height` method. Fixes [https://github.com/gottfrois/image_info/issues/2](https://github.com/gottfrois/image_info/issues/2)
|
data/README.md
CHANGED
@@ -5,13 +5,14 @@
|
|
5
5
|
[](https://gemnasium.com/gottfrois/image_info)
|
6
6
|
[](http://badge.fury.io/rb/image_info)
|
7
7
|
|
8
|
-
ImageInfo finds the size and type of a single or multiple images from the web by fetching as little as needed in batches.
|
8
|
+
ImageInfo finds the size and type of a single or multiple images from the web by fetching as little data as needed (partial image) in batches.
|
9
9
|
|
10
10
|
## Why
|
11
11
|
|
12
12
|
In [LinkThumbnailer](https://github.com/gottfrois/link_thumbnailer) I needed to find images sizes not only for one image.
|
13
13
|
A well known gem like FastImage was not enough so I decided to build my own.
|
14
|
-
The gem use [typhoeus](https://github.com/typhoeus/typhoeus)
|
14
|
+
The gem use [typhoeus](https://github.com/typhoeus/typhoeus)'s parallel requests and stream capability under the hood to
|
15
|
+
get images.
|
15
16
|
|
16
17
|
## Installation
|
17
18
|
|
data/lib/image_info/image.rb
CHANGED
data/lib/image_info/parser.rb
CHANGED
@@ -3,12 +3,11 @@ require 'image_size'
|
|
3
3
|
module ImageInfo
|
4
4
|
class Parser
|
5
5
|
|
6
|
-
attr_reader :image, :
|
6
|
+
attr_reader :image, :data
|
7
7
|
|
8
8
|
def initialize(image, data)
|
9
|
-
@image
|
10
|
-
@
|
11
|
-
@parser = ::ImageSize.new(data)
|
9
|
+
@image = image
|
10
|
+
@data = data
|
12
11
|
end
|
13
12
|
|
14
13
|
def call
|
@@ -26,6 +25,13 @@ module ImageInfo
|
|
26
25
|
def set_image_type
|
27
26
|
image.type = parser.format
|
28
27
|
end
|
29
|
-
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def parser
|
32
|
+
@parser ||= ::ImageSize.new(data)
|
33
|
+
rescue ImageSize::FormatError
|
34
|
+
@parser ||= ::ImageInfo::NullParser.new
|
35
|
+
end
|
30
36
|
end
|
31
37
|
end
|
data/lib/image_info/processor.rb
CHANGED
@@ -1,23 +1,26 @@
|
|
1
1
|
module ImageInfo
|
2
2
|
class RequestHandler
|
3
3
|
|
4
|
-
attr_reader :image
|
4
|
+
attr_reader :image, :buffer
|
5
5
|
|
6
6
|
def initialize(image)
|
7
7
|
@image = image
|
8
|
+
@buffer = StringIO.new
|
8
9
|
end
|
9
10
|
|
10
11
|
def build
|
11
12
|
::Typhoeus::Request.new(image.uri.to_s, followlocation: true, accept_encoding: :gzip).tap do |request|
|
12
|
-
request.
|
13
|
+
request.on_body do |chunk|
|
14
|
+
buffer.write(chunk)
|
15
|
+
:abort if found_image_info?(buffer)
|
16
|
+
end
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
16
20
|
private
|
17
21
|
|
18
|
-
def
|
19
|
-
::ImageInfo::Parser.new(image,
|
22
|
+
def found_image_info?(chunk)
|
23
|
+
::ImageInfo::Parser.new(image, chunk).call
|
20
24
|
end
|
21
|
-
|
22
25
|
end
|
23
26
|
end
|
data/lib/image_info/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_info
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre-Louis Gottfrois
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/image_info/configurable.rb
|
118
118
|
- lib/image_info/configuration.rb
|
119
119
|
- lib/image_info/image.rb
|
120
|
+
- lib/image_info/null_parser.rb
|
120
121
|
- lib/image_info/parser.rb
|
121
122
|
- lib/image_info/processor.rb
|
122
123
|
- lib/image_info/request_handler.rb
|