Class: JekyllImgFlow::AnimatedGifDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-imgflow/animated_gif_detector.rb

Overview

Detects whether a GIF file is animated (contains multiple frames)

Animated GIFs must not be resized or format-converted because the operation would destroy the animation. This class parses the GIF binary format and counts Image Descriptor blocks to determine whether more than one frame is present.

Constant Summary collapse

EXTENSION_INTRODUCER =

GIF block introducer bytes

0x21
IMAGE_DESCRIPTOR =
0x2C
TRAILER =
0x3B

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ AnimatedGifDetector

Returns a new instance of AnimatedGifDetector.

Parameters:

  • path (String)

    Path to the image file



25
26
27
# File 'lib/jekyll-imgflow/animated_gif_detector.rb', line 25

def initialize(path)
  @path = path
end

Class Method Details

.animated?(path) ⇒ Boolean

Check whether the file at path is an animated GIF.

Parameters:

  • path (String)

    Path to the image file

Returns:

  • (Boolean)

    true if the file is a GIF with more than one frame



20
21
22
# File 'lib/jekyll-imgflow/animated_gif_detector.rb', line 20

def self.animated?(path)
  new(path).animated?
end

Instance Method Details

#animated?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/jekyll-imgflow/animated_gif_detector.rb', line 29

def animated?
  return false unless gif?

  frame_count > 1
end