local-fastimage 3.0.2 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 576d4b3064f11a71c592f96929d6f58cb13af056
4
- data.tar.gz: c221b3a5ed155f1f543f9d9de10ac103bd5338b3
2
+ SHA256:
3
+ metadata.gz: 547d7024c4428e2314dd4ae8fe701d6baf57a4d0e735ab3b7d522e65b518be0e
4
+ data.tar.gz: b49ddf7062d328e10a91effc60e8965973d651371de7a3e1e63fd9dba983f37d
5
5
  SHA512:
6
- metadata.gz: cced0adefb5b8523de34918baa5ded500e46cb72ec0208e0f5914e3074ef0a877f60b66083c9a52c7edfa0af7e637f9ff2dda0de7e255bb52dfa1d2b18ef2661
7
- data.tar.gz: 3430d92ceb8e480625f2e506b7ed487ecff9944906e4d387d6240b2cf7adcf022d650a5a90d2e80002846cea841f1c1df0493ebb9de824910fb8a816f2104df8
6
+ metadata.gz: 3b055c6d724144c030c40bfa41fd2dcec29d527abbc71ac7538b481793986799d789790d9c4dc87591b3e7c625af822aca7c82423ad467f9db0041bcb92320d5
7
+ data.tar.gz: dc32631985b2332164e0cdac9bbc9d2fec7d8605f54cafc1444c2ef16a42aba4b7c324b9d5501ac202b361502fd73f28046ac0e4ae718a8afbc1f24ac4a07bdf
@@ -1,8 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.9
4
- - 2.2.5
5
- - 2.3.1
3
+ - 2.2.10
4
+ - 2.3.7
5
+ - 2.4.4
6
+ - 2.5.1
6
7
 
7
8
  before_install:
8
9
  - gem install bundler
@@ -1,3 +1,9 @@
1
+ # 3.1.0 - 2018-04-24
2
+
3
+ Updates code to match fastimage v2.1.1
4
+
5
+ * improved SVG support
6
+
1
7
  # 3.0.2 - 2016-10-17
2
8
 
3
9
  Fixes a bug,
@@ -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
- Fastimage can also read local (and other) files - anything that is not parseable as a URI will be
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 :read - for
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 :proxy argument if you want to specify the proxy address in the call.
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 :timeout => number_of_seconds.
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 will nil if it encounters an error, but you can pass :raise_on_failure => true to get an exception.
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 :http_header argument to specify headers, e.g., :http_header => {'User-Agent' => 'Fake Browser'}.
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. But take care to sanitise the strings passed to FastImage; it will try to read from whatever is passed.
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
 
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fastimage"
5
+
6
+ require "irb"
7
+ IRB.start
@@ -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 "<s", "<?"
326
- # Does not handle UTF-16 or other multi-byte encodings
327
- :svg if @stream.peek(64).include?("<svg")
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
- @exif = Exif.new(IOStream.new(io)) rescue nil
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 @exif && @exif.rotated?
385
- return [width, height, @exif ? @exif.orientation : 1]
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
- @ratio = values[2].to_f / values[3].to_f
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class FastImage
2
- VERSION = "3.0.2"
4
+ VERSION = "3.1.0"
3
5
  end
@@ -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 given its uri by fetching as little as needed."
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", "~> 1.12"
22
- s.add_development_dependency "rake", "~> 10.0"
23
- s.add_development_dependency "minitest", "~> 5.0"
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.2
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: 2016-10-17 00:00:00.000000000 Z
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: '1.12'
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: '1.12'
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: '10.0'
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: '10.0'
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: '5.0'
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: '5.0'
56
- description: Local FastImage finds the size or type of an image given its uri by fetching
57
- as little as needed.
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.5.1
98
+ rubygems_version: 2.7.6
98
99
  signing_key:
99
100
  specification_version: 4
100
101
  summary: Local FastImage - Image info fast