local-fastimage 3.0.2 → 3.1.0
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 +5 -5
- data/.travis.yml +4 -3
- data/CHANGELOG.md +6 -0
- data/README.textile +12 -9
- data/bin/console +7 -0
- data/lib/fastimage.rb +32 -9
- data/lib/fastimage/version.rb +3 -1
- data/local-fastimage.gemspec +4 -4
- metadata +18 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 547d7024c4428e2314dd4ae8fe701d6baf57a4d0e735ab3b7d522e65b518be0e
|
4
|
+
data.tar.gz: b49ddf7062d328e10a91effc60e8965973d651371de7a3e1e63fd9dba983f37d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b055c6d724144c030c40bfa41fd2dcec29d527abbc71ac7538b481793986799d789790d9c4dc87591b3e7c625af822aca7c82423ad467f9db0041bcb92320d5
|
7
|
+
data.tar.gz: dc32631985b2332164e0cdac9bbc9d2fec7d8605f54cafc1444c2ef16a42aba4b7c324b9d5501ac202b361502fd73f28046ac0e4ae718a8afbc1f24ac4a07bdf
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.textile
CHANGED
@@ -22,29 +22,27 @@ You only need supply the uri, and FastImage will do the rest.
|
|
22
22
|
|
23
23
|
h2. Features
|
24
24
|
|
25
|
-
|
26
|
-
interpreted as a filename, and FastImage will attempt to open it with File#open.
|
25
|
+
FastImage can also read local (and other) files - anything that is not parseable as a URI will be interpreted as a filename, and FastImage will attempt to open it with @File#open@.
|
27
26
|
|
28
|
-
FastImage will also automatically read from any object that responds to
|
29
|
-
instance an IO object if that is passed instead of a URI.
|
27
|
+
FastImage will also automatically read from any object that responds to @:read@ - for instance an IO object if that is passed instead of a URI.
|
30
28
|
|
31
29
|
FastImage will follow up to 4 HTTP redirects to get the image.
|
32
30
|
|
33
|
-
FastImage will obey the http_proxy setting in your environment to route requests via a proxy. You can also pass a
|
31
|
+
FastImage will obey the @http_proxy@ setting in your environment to route requests via a proxy. You can also pass a @:proxy@ argument if you want to specify the proxy address in the call.
|
34
32
|
|
35
|
-
You can add a timeout to the request which will limit the request time by passing
|
33
|
+
You can add a timeout to the request which will limit the request time by passing @:timeout => number_of_seconds@.
|
36
34
|
|
37
|
-
FastImage normally replies
|
35
|
+
FastImage normally replies with @nil@ if it encounters an error, but you can pass @:raise_on_failure => true@ to get an exception.
|
38
36
|
|
39
37
|
FastImage also provides a reader for the content length header provided in HTTP. This may be useful to assess the file size of an image, but do not rely on it exclusively - it will not be present in chunked responses for instance.
|
40
38
|
|
41
|
-
FastImage accepts additional HTTP headers. This can be used to set a user agent or referrer which some servers require. Pass an
|
39
|
+
FastImage accepts additional HTTP headers. This can be used to set a user agent or referrer which some servers require. Pass an @:http_header@ argument to specify headers, e.g., @:http_header => {'User-Agent' => 'Fake Browser'}@.
|
42
40
|
|
43
41
|
FastImage can give you information about the parsed display orientation of an image with Exif data (jpeg or tiff).
|
44
42
|
|
45
43
|
h2. Security
|
46
44
|
|
47
|
-
As of v1.6.7 FastImage no longer uses openuri to open files, but directly calls File.open
|
45
|
+
As of v1.6.7 FastImage no longer uses @openuri@ to open files, but directly calls @File.open@. Take care to sanitise the strings passed to FastImage; it will try to read from whatever is passed.
|
48
46
|
|
49
47
|
h2. Examples
|
50
48
|
|
@@ -93,6 +91,10 @@ h2. Documentation
|
|
93
91
|
|
94
92
|
"http://sdsykes.github.io/fastimage/rdoc/FastImage.html":http://sdsykes.github.io/fastimage/rdoc/FastImage.html
|
95
93
|
|
94
|
+
h2. Maintainer
|
95
|
+
|
96
|
+
FastImage is maintained by Stephen Sykes (@sdsykes). Support this project by using "LibPixel":https://libpixel.com cloud based image resizing and processing service.
|
97
|
+
|
96
98
|
h2. Benchmark
|
97
99
|
|
98
100
|
It's way faster than conventional methods (for example the image_size gem) for most types of file when fetching over the wire.
|
@@ -152,6 +154,7 @@ h2. FastImage in other languages
|
|
152
154
|
* "PHP by tommoor":https://github.com/tommoor/fastimage
|
153
155
|
* "Node.js by ShogunPanda":https://github.com/ShogunPanda/fastimage
|
154
156
|
* "Objective C by kylehickinson":https://github.com/kylehickinson/FastImage
|
157
|
+
* "Android by qstumn":https://github.com/qstumn/FastImageSize
|
155
158
|
|
156
159
|
h2. Licence
|
157
160
|
|
data/bin/console
ADDED
data/lib/fastimage.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# coding: ASCII-8BIT
|
2
3
|
|
3
4
|
# FastImage finds the size or type of an image given its path. FastImage knows
|
@@ -139,6 +140,8 @@ class FastImage
|
|
139
140
|
|
140
141
|
@property = @options[:type_only] ? :type : :size
|
141
142
|
|
143
|
+
@type, @state = nil
|
144
|
+
|
142
145
|
if @source.respond_to?(:read)
|
143
146
|
@path = @source.path if @source.respond_to? :path
|
144
147
|
fetch_using_read
|
@@ -254,6 +257,7 @@ class FastImage
|
|
254
257
|
@str = ''
|
255
258
|
end
|
256
259
|
|
260
|
+
# Peeking beyond the end of the input will raise
|
257
261
|
def peek(n)
|
258
262
|
while @strpos + n - 1 >= @str.size
|
259
263
|
unused_str = @str[@strpos..-1]
|
@@ -322,11 +326,17 @@ class FastImage
|
|
322
326
|
end
|
323
327
|
when "RI"
|
324
328
|
:webp if @stream.peek(12)[8..11] == "WEBP"
|
325
|
-
when
|
326
|
-
#
|
327
|
-
|
329
|
+
when '<s', /<[?!]/
|
330
|
+
# Peek 10 more chars each time, and if end of file is reached just raise
|
331
|
+
# unknown. We assume the <svg tag cannot be within 10 chars of the end of
|
332
|
+
# the file, and is within the first 250 chars.
|
333
|
+
begin
|
334
|
+
:svg if (1..25).detect {|n| @stream.peek(10 * n).include?("<svg")}
|
335
|
+
rescue FiberError, CannotParseImage
|
336
|
+
nil
|
337
|
+
end
|
328
338
|
end
|
329
|
-
|
339
|
+
|
330
340
|
parsed_type or raise UnknownImageType
|
331
341
|
end
|
332
342
|
|
@@ -346,6 +356,7 @@ class FastImage
|
|
346
356
|
end
|
347
357
|
|
348
358
|
def parse_size_for_jpeg
|
359
|
+
exif = nil
|
349
360
|
loop do
|
350
361
|
@state = case @state
|
351
362
|
when nil
|
@@ -361,7 +372,7 @@ class FastImage
|
|
361
372
|
io = StringIO.new(data)
|
362
373
|
if io.read(4) == "Exif"
|
363
374
|
io.read(2)
|
364
|
-
|
375
|
+
exif = Exif.new(IOStream.new(io)) rescue nil
|
365
376
|
end
|
366
377
|
:started
|
367
378
|
when 0xe0..0xef
|
@@ -381,8 +392,8 @@ class FastImage
|
|
381
392
|
@stream.skip(3)
|
382
393
|
height = @stream.read_int
|
383
394
|
width = @stream.read_int
|
384
|
-
width, height = height, width if
|
385
|
-
return [width, height,
|
395
|
+
width, height = height, width if exif && exif.rotated?
|
396
|
+
return [width, height, exif ? exif.orientation : 1]
|
386
397
|
end
|
387
398
|
end
|
388
399
|
end
|
@@ -445,6 +456,7 @@ class FastImage
|
|
445
456
|
|
446
457
|
def initialize(stream)
|
447
458
|
@stream = stream
|
459
|
+
@width, @height, @orientation = nil
|
448
460
|
parse_exif
|
449
461
|
end
|
450
462
|
|
@@ -524,6 +536,7 @@ class FastImage
|
|
524
536
|
class Svg # :nodoc:
|
525
537
|
def initialize(stream)
|
526
538
|
@stream = stream
|
539
|
+
@width, @height, @ratio, @viewbox_width, @viewbox_height = nil
|
527
540
|
parse_svg
|
528
541
|
end
|
529
542
|
|
@@ -534,6 +547,10 @@ class FastImage
|
|
534
547
|
[@width, @width / @ratio]
|
535
548
|
elsif @height && @ratio
|
536
549
|
[@height * @ratio, @height]
|
550
|
+
elsif @viewbox_width && @viewbox_height
|
551
|
+
[@viewbox_width, @viewbox_height]
|
552
|
+
else
|
553
|
+
nil
|
537
554
|
end
|
538
555
|
end
|
539
556
|
|
@@ -556,14 +573,20 @@ class FastImage
|
|
556
573
|
return if @width
|
557
574
|
elsif attr_name.join =~ /viewbox/i
|
558
575
|
values = attr_value.split(/\s/)
|
559
|
-
|
576
|
+
if values[2].to_f > 0 && values[3].to_f > 0
|
577
|
+
@ratio = values[2].to_f / values[3].to_f
|
578
|
+
@viewbox_width = values[2].to_i
|
579
|
+
@viewbox_height = values[3].to_i
|
580
|
+
end
|
560
581
|
end
|
561
582
|
when /\w/
|
562
583
|
attr_name << char
|
584
|
+
when "<"
|
585
|
+
attr_name = [char]
|
563
586
|
when ">"
|
564
587
|
state = :stop if state == :started
|
565
588
|
else
|
566
|
-
state = :started if attr_name.join == "svg"
|
589
|
+
state = :started if attr_name.join == "<svg"
|
567
590
|
attr_name.clear
|
568
591
|
end
|
569
592
|
end
|
data/lib/fastimage/version.rb
CHANGED
data/local-fastimage.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ["sdsykes@gmail.com", "gregor@plan.io", "support@plan.io"]
|
11
11
|
|
12
12
|
s.summary = "Local FastImage - Image info fast"
|
13
|
-
s.description = "Local FastImage finds the size or type of an image
|
13
|
+
s.description = "Local FastImage finds the size or type of an image reading as little bytes as needed."
|
14
14
|
s.homepage = "https://github.com/planio-gmbh/local-fastimage"
|
15
15
|
|
16
16
|
s.license = "MIT"
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_development_dependency "bundler"
|
22
|
-
s.add_development_dependency "rake"
|
23
|
-
s.add_development_dependency "minitest"
|
21
|
+
s.add_development_dependency "bundler"
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_development_dependency "minitest"
|
24
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: local-fastimage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Sykes
|
@@ -9,52 +9,52 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-04-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '0'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
41
|
+
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: minitest
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - "
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - "
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
56
|
-
description: Local FastImage finds the size or type of an image
|
57
|
-
|
55
|
+
version: '0'
|
56
|
+
description: Local FastImage finds the size or type of an image reading as little
|
57
|
+
bytes as needed.
|
58
58
|
email:
|
59
59
|
- sdsykes@gmail.com
|
60
60
|
- gregor@plan.io
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- README.md
|
72
72
|
- README.textile
|
73
73
|
- Rakefile
|
74
|
+
- bin/console
|
74
75
|
- lib/fastimage.rb
|
75
76
|
- lib/fastimage/version.rb
|
76
77
|
- local-fastimage.gemspec
|
@@ -94,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
95
|
version: '0'
|
95
96
|
requirements: []
|
96
97
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.7.6
|
98
99
|
signing_key:
|
99
100
|
specification_version: 4
|
100
101
|
summary: Local FastImage - Image info fast
|