Method: Renchin::CLI#cgraph

Defined in:
lib/renchin/cli.rb

#cgraphObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/renchin/cli.rb', line 94

def cgraph
  gif_file = options[:input]
  result_file = options[:output]
  gif_configs = (`identify ~/Downloads/notch_belt.gif`).split("\n")
  pingpong = 0 # comment this if you dont want a pingpong loop
  frame_start = options[:frame_start]
  frame_stop = options[:frame_end]
  frame_bg = options[:frame_bg]
  overlay_x = options[:overlay_x]
  overlay_y = options[:overlay_y]
  overlay_w = options[:overlay_w]
  overlay_h = options[:overlay_h]
  viewport_x = options[:viewport_x]
  viewport_y = options[:viewport_y]
  viewport_w = options[:viewport_w] || gif_configs[0].split(" ")[2].split("x")[0]
  viewport_h = options[:viewport_h] || gif_configs[0].split(" ")[2].split("x")[1]
  speed_current = options[:duration]
  frames = ""
  offset = 0

  image_directory_path = image_directory(__method__)

  # movie_to_frame
  system("convert #{gif_file}[#{frame_bg}] #{image_directory_path}/bg.png")
  system("convert #{gif_file} -repage 0x0 -crop #{overlay_w}x#{overlay_h}+#{overlay_x}+#{overlay_y} +repage #{image_directory_path}/frame.png")

  # frames_to_gif && iterate_frames
  frame_stop = (`identify #{gif_file} | wc -l`).chomp.gsub(/\s/,'').to_i
  for i in frame_start...frame_stop do
    frames = "#{frames} -delay #{speed_current} #{image_directory_path}/frame-out-#{offset}.png"
    system("convert #{image_directory_path}/bg.png #{image_directory_path}/frame-#{i}.png -geometry +#{overlay_x}+#{overlay_y} -compose over -composite #{image_directory_path}/frame-out-#{offset}.png")
    offset += 1
  end
  system("convert #{frames} -loop 0 -crop #{viewport_w}x#{viewport_h}+#{viewport_x}+#{viewport_y} -layers Optimize #{result_file}")


  delete_directory(image_directory_path, "\.(jpg|png)")
  say("Renchin generated sprite file! ~> #{result_file}", :green)
end