fastimage 2.2.0 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.textile +2 -1
  3. data/lib/fastimage.rb +38 -29
  4. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53c0966ef5216c189e2950b1ad36c106777175f0d4dca9851abd34472fd9cb61
4
- data.tar.gz: 29f5a6bc03623e184166e7f9c5e8c4379011b301904d4c690037d5b7b0ba0b33
3
+ metadata.gz: 4124655c4f8af69e9b8bf9bfa433a11161e9ea97c23e755a196555012eadf75b
4
+ data.tar.gz: 40fef6aa908fc14799f2cb53e80d5081bef11ce0482d86c5947841fb29ee9604
5
5
  SHA512:
6
- metadata.gz: 28e8ec4debe6c2c477da19cafb1ad41e5de4d809136bd86621ae128372c32c1259abea833856f73dfcfe8ef3444bc5e1a148f91b52ee02d3292235c4d95fc542
7
- data.tar.gz: ba8b4c6bb42146387b1a8af718fbbaf74a9a94532ee5adce082ff676095dad5d5e0eb613f1ec41d7729709847195fa81c4614f2d9d510d6c7def67f8970f168e
6
+ metadata.gz: 205fb43dacd3239f8425dd8cbd311be8c375f3c377cbf71771b87304b0c62780905a366783b1b5606e7386edf9ed2fe1cab138b8a20ad47f238150d5143b93db
7
+ data.tar.gz: 219ac67b55c23bb59458fc57d165a76c0bf5855c971c705d033103c01848cbb9f3fb4a1e8024419192ced93f076d223fb6e3ce77289b8ed94858d0e58c5387df
data/README.textile CHANGED
@@ -132,7 +132,7 @@ h2. Tests
132
132
 
133
133
  You'll need to @gem install fakeweb@ and possibly also @gem install test-unit@ to be able to run the tests.
134
134
 
135
- bc.. $ ruby test.rb
135
+ bc.. $ ruby test/test.rb
136
136
  Run options:
137
137
 
138
138
  # Running tests:
@@ -156,6 +156,7 @@ h2. FastImage in other languages
156
156
  * "Node.js by ShogunPanda":https://github.com/ShogunPanda/fastimage
157
157
  * "Objective C by kylehickinson":https://github.com/kylehickinson/FastImage
158
158
  * "Android by qstumn":https://github.com/qstumn/FastImageSize
159
+ * "Flutter by ky1vstar":https://github.com/ky1vstar/fastimage.dart
159
160
 
160
161
  h2. Licence
161
162
 
data/lib/fastimage.rb CHANGED
@@ -251,10 +251,8 @@ class FastImage
251
251
  Errno::ENETUNREACH, ImageFetchFailure, Net::HTTPBadResponse, EOFError, Errno::ENOENT,
252
252
  OpenSSL::SSL::SSLError
253
253
  raise ImageFetchFailure if @options[:raise_on_failure]
254
- rescue NoMethodError # 1.8.7p248 can raise this due to a net/http bug
255
- raise ImageFetchFailure if @options[:raise_on_failure]
256
254
  rescue UnknownImageType
257
- raise UnknownImageType if @options[:raise_on_failure]
255
+ raise if @options[:raise_on_failure]
258
256
  rescue CannotParseImage
259
257
  if @options[:raise_on_failure]
260
258
  if @property == :size
@@ -434,8 +432,11 @@ class FastImage
434
432
  end
435
433
 
436
434
  def fetch_using_base64(uri)
437
- data = uri.split(',')[1]
438
- decoded = Base64.decode64(data)
435
+ decoded = begin
436
+ Base64.decode64(uri.split(',')[1])
437
+ rescue
438
+ raise CannotParseImage
439
+ end
439
440
  @content_length = decoded.size
440
441
  fetch_using_read StringIO.new(decoded)
441
442
  end
@@ -471,19 +472,20 @@ class FastImage
471
472
 
472
473
  # Peeking beyond the end of the input will raise
473
474
  def peek(n)
474
- while @strpos + n - 1 >= @str.size
475
+ while @strpos + n > @str.size
475
476
  unused_str = @str[@strpos..-1]
477
+
476
478
  new_string = @read_fiber.resume
479
+ new_string = @read_fiber.resume if new_string.is_a? Net::ReadAdapter
477
480
  raise CannotParseImage if !new_string
478
-
479
481
  # we are dealing with bytes here, so force the encoding
480
- new_string.force_encoding("ASCII-8BIT") if String.method_defined? :force_encoding
482
+ new_string.force_encoding("ASCII-8BIT") if new_string.respond_to? :force_encoding
481
483
 
482
484
  @str = unused_str + new_string
483
485
  @strpos = 0
484
486
  end
485
487
 
486
- @str[@strpos..(@strpos + n - 1)]
488
+ @str[@strpos, n]
487
489
  end
488
490
 
489
491
  def read(n)
@@ -501,7 +503,7 @@ class FastImage
501
503
  new_string = @read_fiber.resume
502
504
  raise CannotParseImage if !new_string
503
505
 
504
- new_string.force_encoding("ASCII-8BIT") if String.method_defined? :force_encoding
506
+ new_string.force_encoding("ASCII-8BIT") if new_string.respond_to? :force_encoding
505
507
 
506
508
  fetched += new_string.size
507
509
  @str = new_string
@@ -545,7 +547,7 @@ class FastImage
545
547
  :webp if @stream.peek(12)[8..11] == "WEBP"
546
548
  when "<s"
547
549
  :svg if @stream.peek(4) == "<svg"
548
- when /<[?!]/
550
+ when /\s\s|\s<|<[?!]/
549
551
  # Peek 10 more chars each time, and if end of file is reached just raise
550
552
  # unknown. We assume the <svg tag cannot be within 10 chars of the end of
551
553
  # the file, and is within the first 250 chars.
@@ -578,38 +580,45 @@ class FastImage
578
580
  # Checks if a delay between frames exists and if it does, then the GIFs is
579
581
  # animated
580
582
  def animated?
581
- delay = 0
583
+ frames = 0
582
584
 
583
- @stream.read(10) # "GIF" + version (3) + width (2) + height (2)
585
+ # "GIF" + version (3) + width (2) + height (2)
586
+ @stream.skip(10)
584
587
 
585
- fields = @stream.read(3).unpack("C")[0] # fields (1) + bg color (1) + pixel ratio (1)
586
-
587
- # Skip Global Color Table if it exists
588
- if fields & 0x80
588
+ # fields (1) + bg color (1) + pixel ratio (1)
589
+ fields = @stream.read(3).unpack("CCC")[0]
590
+ if fields & 0x80 != 0 # Global Color Table
589
591
  # 2 * (depth + 1) colors, each occupying 3 bytes (RGB)
590
592
  @stream.skip(3 * 2 ** ((fields & 0x7) + 1))
591
593
  end
592
594
 
593
595
  loop do
594
596
  block_type = @stream.read(1).unpack("C")[0]
595
- if block_type == 0x21
596
- extension_type = @stream.read(1).unpack("C")[0]
597
- size = @stream.read(1).unpack("C")[0]
598
- if extension_type == 0xF9
599
- delay = @stream.read(4).unpack("CSC")[1] # fields (1) + delay (2) + transparent index (1)
600
- break
601
- elsif extension_type == 0xFF
602
- @stream.skip(size) # application ID (8) + version (3)
603
- else
604
- return # unrecognized extension
597
+
598
+ if block_type == 0x21 # Graphic Control Extension
599
+ # extension type (1) + size (1)
600
+ size = @stream.read(2).unpack("CC")[1]
601
+ @stream.skip(size)
602
+ skip_sub_blocks
603
+ elsif block_type == 0x2C # Image Descriptor
604
+ frames += 1
605
+ return true if frames > 1
606
+
607
+ # left position (2) + top position (2) + width (2) + height (2) + fields (1)
608
+ fields = @stream.read(9).unpack("SSSSC")[4]
609
+ if fields & 0x80 != 0 # Local Color Table
610
+ # 2 * (depth + 1) colors, each occupying 3 bytes (RGB)
611
+ @stream.skip(3 * 2 ** ((fields & 0x7) + 1))
605
612
  end
613
+
614
+ @stream.skip(1) # LZW min code size (1)
606
615
  skip_sub_blocks
607
616
  else
608
- return # unrecognized block
617
+ break # unrecognized block
609
618
  end
610
619
  end
611
620
 
612
- delay > 0
621
+ false
613
622
  end
614
623
 
615
624
  private
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: 2.2.0
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Sykes
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-23 00:00:00.000000000 Z
11
+ date: 2021-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fakeweb-fi
@@ -81,7 +81,7 @@ homepage: http://github.com/sdsykes/fastimage
81
81
  licenses:
82
82
  - MIT
83
83
  metadata: {}
84
- post_install_message:
84
+ post_install_message:
85
85
  rdoc_options:
86
86
  - "--charset=UTF-8"
87
87
  require_paths:
@@ -97,8 +97,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  requirements: []
100
- rubygems_version: 3.0.6
101
- signing_key:
100
+ rubygems_version: 3.2.3
101
+ signing_key:
102
102
  specification_version: 4
103
103
  summary: FastImage - Image info fast
104
104
  test_files: []