Class: Shellfie::GifGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/shellfie/gif_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ GifGenerator

Returns a new instance of GifGenerator.



19
20
21
22
23
24
# File 'lib/shellfie/gif_generator.rb', line 19

def initialize(config)
  @config = config
  @renderer = Renderer.new(config)
  @theme = @renderer.theme
  @frame_builder = AnimationFrameBuilder.new(config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



17
18
19
# File 'lib/shellfie/gif_generator.rb', line 17

def config
  @config
end

#themeObject (readonly)

Returns the value of attribute theme.



17
18
19
# File 'lib/shellfie/gif_generator.rb', line 17

def theme
  @theme
end

Instance Method Details

#generate(output_path, scale: 1, shadow: true, transparent: false, format: nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/shellfie/gif_generator.rb', line 26

def generate(output_path, scale: 1, shadow: true, transparent: false, format: nil)
  check_dependencies!

  images = []
  chrome_cache = RenderChromeCache.new
  begin
    frames = build_animation_frames
    validate_frame_limit!(frames)
    warn_frame_count(frames)
    images = render_frames(frames, scale: scale, shadow: shadow, transparent: transparent, chrome_cache: chrome_cache)
    extension = FormatResolver.resolve(output_path, explicit: format, default: "gif")
    OutputWriter.write(output_path, extension: extension) do |temporary_path|
      combine_to_animation(images, temporary_path, format: extension)
    end
  ensure
    cleanup_temp_files(images)
    chrome_cache.cleanup
  end
rescue MiniMagick::Error => e
  raise RenderError.new("ImageMagick animation render failed: #{e.message}", category: :render)
end