Class: FastImage::Gif
- Inherits:
-
Object
- Object
- FastImage::Gif
- Defined in:
- lib/fastimage.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#animated? ⇒ Boolean
Checks if a delay between frames exists and if it does, then the GIFs is animated.
-
#initialize(stream) ⇒ Gif
constructor
A new instance of Gif.
- #width_and_height ⇒ Object
Constructor Details
#initialize(stream) ⇒ Gif
Returns a new instance of Gif.
572 573 574 |
# File 'lib/fastimage.rb', line 572 def initialize(stream) @stream = stream end |
Instance Method Details
#animated? ⇒ Boolean
Checks if a delay between frames exists and if it does, then the GIFs is animated
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 |
# File 'lib/fastimage.rb', line 582 def animated? frames = 0 # "GIF" + version (3) + width (2) + height (2) @stream.skip(10) # fields (1) + bg color (1) + pixel ratio (1) fields = @stream.read(3).unpack("CCC")[0] if fields & 0x80 != 0 # Global Color Table # 2 * (depth + 1) colors, each occupying 3 bytes (RGB) @stream.skip(3 * 2 ** ((fields & 0x7) + 1)) end loop do block_type = @stream.read(1).unpack("C")[0] if block_type == 0x21 # Graphic Control Extension # extension type (1) + size (1) size = @stream.read(2).unpack("CC")[1] @stream.skip(size) skip_sub_blocks elsif block_type == 0x2C # Image Descriptor frames += 1 return true if frames > 1 # left position (2) + top position (2) + width (2) + height (2) + fields (1) fields = @stream.read(9).unpack("SSSSC")[4] if fields & 0x80 != 0 # Local Color Table # 2 * (depth + 1) colors, each occupying 3 bytes (RGB) @stream.skip(3 * 2 ** ((fields & 0x7) + 1)) end @stream.skip(1) # LZW min code size (1) skip_sub_blocks else break # unrecognized block end end false end |
#width_and_height ⇒ Object
576 577 578 |
# File 'lib/fastimage.rb', line 576 def width_and_height @stream.read(11)[6..10].unpack('SS') end |