Class: VivlioStarter::CLI::PreProcessCommands::TalkAvatarGenerator::AvatarTools

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio_starter/cli/pre_process/talk_avatar_generator.rb

Overview

外部ツール依存をこのクラスへ隔離する(生成ロジックは純粋なまま保つ)。

Instance Method Summary collapse

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


140
141
142
143
144
# File 'lib/vivlio_starter/cli/pre_process/talk_avatar_generator.rb', line 140

def available?
  return @available unless @available.nil?

  @available = system('magick', '-version', out: File::NULL, err: File::NULL) || false
end

#render(path, glyph:, background:, foreground:, font:) ⇒ Boolean

単色地に 1 文字を中央配置した正方形画像を書き出す。

Returns:

  • (Boolean)

    生成できたか



148
149
150
151
152
153
154
155
156
# File 'lib/vivlio_starter/cli/pre_process/talk_avatar_generator.rb', line 148

def render(path, glyph:, background:, foreground:, font:)
  args = ['magick', '-size', "#{EDGE}x#{EDGE}", "xc:#{background}",
          '-gravity', 'center', '-fill', foreground]
  args += ['-font', font] if File.exist?(font)
  args += ['-pointsize', POINTSIZE.to_s, '-annotate', '0', glyph, path]
  system(*args, out: File::NULL, err: File::NULL) && File.exist?(path)
rescue StandardError
  false
end