fastimage 2.2.5 → 2.2.7
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/README.textile +1 -1
- data/lib/fastimage/version.rb +3 -1
- data/lib/fastimage.rb +47 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0365d74877c5c9bb640ef13fb701665b8fc511027ceba510be2cec62de03584c
|
4
|
+
data.tar.gz: d15af188ae269215bce75d21d1f796680bd66a488367ab9a935919b50fe10a68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9b26747ff490133917388f29203c1d8272dfe88c28b9a5208a3df1a55728779c3cfe203784c6df9d1bca91bcf58df0cf64e60220a468a0c9f6ca4f47963b3e0
|
7
|
+
data.tar.gz: aa8f0a007f6cb710cbcea70241a56b9fd98fd54bb1a553be7c5533fca7b125b7df99ffbf5dcf5e996d87f60eb8a83933fd49aba848fc4a93c85ac540c8ae1577
|
data/README.textile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
!https://img.shields.io/gem/dt/fastimage.svg!:https://rubygems.org/gems/fastimage
|
2
|
-
!https://
|
2
|
+
!https://github.com/sdsykes/fastimage/actions/workflows/test.yml/badge.svg?branch=master!:https://github.com/sdsykes/fastimage/actions/workflows/test.yml
|
3
3
|
|
4
4
|
h1. FastImage
|
5
5
|
|
data/lib/fastimage/version.rb
CHANGED
data/lib/fastimage.rb
CHANGED
@@ -85,6 +85,8 @@ class FastImage
|
|
85
85
|
end
|
86
86
|
class CannotParseImage < FastImageException # :nodoc:
|
87
87
|
end
|
88
|
+
class BadImageURI < FastImageException # :nodoc:
|
89
|
+
end
|
88
90
|
|
89
91
|
DefaultTimeout = 2 unless const_defined?(:DefaultTimeout)
|
90
92
|
|
@@ -228,6 +230,8 @@ class FastImage
|
|
228
230
|
:size
|
229
231
|
end
|
230
232
|
|
233
|
+
raise BadImageURI if uri.nil?
|
234
|
+
|
231
235
|
@type, @state = nil
|
232
236
|
|
233
237
|
if uri.respond_to?(:read)
|
@@ -254,7 +258,7 @@ class FastImage
|
|
254
258
|
Errno::ENETUNREACH, ImageFetchFailure, Net::HTTPBadResponse, EOFError, Errno::ENOENT,
|
255
259
|
OpenSSL::SSL::SSLError
|
256
260
|
raise ImageFetchFailure if @options[:raise_on_failure]
|
257
|
-
rescue UnknownImageType
|
261
|
+
rescue UnknownImageType, BadImageURI
|
258
262
|
raise if @options[:raise_on_failure]
|
259
263
|
rescue CannotParseImage
|
260
264
|
if @options[:raise_on_failure]
|
@@ -431,7 +435,7 @@ class FastImage
|
|
431
435
|
|
432
436
|
def parse_animated
|
433
437
|
@type = parse_type unless @type
|
434
|
-
@type
|
438
|
+
%i(gif webp avif).include?(@type) ? send("parse_animated_for_#{@type}") : nil
|
435
439
|
end
|
436
440
|
|
437
441
|
def fetch_using_base64(uri)
|
@@ -544,12 +548,11 @@ class FastImage
|
|
544
548
|
case @stream.peek(3).bytes.to_a.last
|
545
549
|
when 0
|
546
550
|
# http://www.ftyps.com/what.html
|
547
|
-
# HEIC is composed of nested "boxes". Each box has a header composed of
|
548
|
-
# - Size (32 bit integer)
|
549
|
-
# - Box type (4 chars)
|
550
|
-
# - Extended size: only if size === 1, the type field is followed by 64 bit integer of extended size
|
551
|
-
# - Payload: Type-dependent
|
552
551
|
case @stream.peek(12)[4..-1]
|
552
|
+
when "ftypavif"
|
553
|
+
:avif
|
554
|
+
when "ftypavis"
|
555
|
+
:avif
|
553
556
|
when "ftypheic"
|
554
557
|
:heic
|
555
558
|
when "ftypmif1"
|
@@ -584,7 +587,14 @@ class FastImage
|
|
584
587
|
end
|
585
588
|
alias_method :parse_size_for_cur, :parse_size_for_ico
|
586
589
|
|
587
|
-
|
590
|
+
# HEIC/AVIF are a special case of the general ISO_BMFF format, in which all data is encapsulated in typed boxes,
|
591
|
+
# with a mandatory ftyp box that is used to indicate particular file types. Is composed of nested "boxes". Each
|
592
|
+
# box has a header composed of
|
593
|
+
# - Size (32 bit integer)
|
594
|
+
# - Box type (4 chars)
|
595
|
+
# - Extended size: only if size === 1, the type field is followed by 64 bit integer of extended size
|
596
|
+
# - Payload: Type-dependent
|
597
|
+
class IsoBmff # :nodoc:
|
588
598
|
def initialize(stream)
|
589
599
|
@stream = stream
|
590
600
|
end
|
@@ -735,14 +745,19 @@ class FastImage
|
|
735
745
|
end
|
736
746
|
end
|
737
747
|
|
748
|
+
def parse_size_for_avif
|
749
|
+
bmff = IsoBmff.new(@stream)
|
750
|
+
bmff.width_and_height
|
751
|
+
end
|
752
|
+
|
738
753
|
def parse_size_for_heic
|
739
|
-
|
740
|
-
|
754
|
+
bmff = IsoBmff.new(@stream)
|
755
|
+
bmff.width_and_height
|
741
756
|
end
|
742
757
|
|
743
758
|
def parse_size_for_heif
|
744
|
-
|
745
|
-
|
759
|
+
bmff = IsoBmff.new(@stream)
|
760
|
+
bmff.width_and_height
|
746
761
|
end
|
747
762
|
|
748
763
|
class Gif # :nodoc:
|
@@ -1079,4 +1094,24 @@ class FastImage
|
|
1079
1094
|
gif = Gif.new(@stream)
|
1080
1095
|
gif.animated?
|
1081
1096
|
end
|
1097
|
+
|
1098
|
+
def parse_animated_for_webp
|
1099
|
+
vp8 = @stream.read(16)[12..15]
|
1100
|
+
_len = @stream.read(4).unpack("V")
|
1101
|
+
case vp8
|
1102
|
+
when "VP8 "
|
1103
|
+
false
|
1104
|
+
when "VP8L"
|
1105
|
+
false
|
1106
|
+
when "VP8X"
|
1107
|
+
flags = @stream.read(4).unpack("C")[0]
|
1108
|
+
flags & 2 > 0
|
1109
|
+
else
|
1110
|
+
nil
|
1111
|
+
end
|
1112
|
+
end
|
1113
|
+
|
1114
|
+
def parse_animated_for_avif
|
1115
|
+
@stream.peek(12)[4..-1] == "ftypavis"
|
1116
|
+
end
|
1082
1117
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastimage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Sykes
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
|
-
rubygems_version: 3.
|
101
|
+
rubygems_version: 3.4.6
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: FastImage - Image info fast
|