Class: VivlioStarter::CLI::PreProcessCommands::TalkAvatarGenerator::AvatarTools
- Inherits:
-
Object
- Object
- VivlioStarter::CLI::PreProcessCommands::TalkAvatarGenerator::AvatarTools
- Defined in:
- lib/vivlio_starter/cli/pre_process/talk_avatar_generator.rb
Overview
外部ツール依存をこのクラスへ隔離する(生成ロジックは純粋なまま保つ)。
Instance Method Summary collapse
- #available? ⇒ Boolean
-
#render(path, glyph:, background:, foreground:, font:) ⇒ Boolean
単色地に 1 文字を中央配置した正方形画像を書き出す。.
Instance Method Details
#available? ⇒ 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 文字を中央配置した正方形画像を書き出す。
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 |