44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/ios_icon_generator/cli/commands/stub.rb', line 44
def call(text:, xcasset_folder:, type:, **options)
raise "#{'ImageMagick'.blue.bold} is required. It can be installed via #{'homebrew'.bold.underlined} using #{'brew install imagemagick'.blue.bold.underlined}" unless Library.which('magick')
types = type.map(&:to_sym)
progress_bar = ProgressBar.create(total: nil)
parallel_processes = options.fetch(:parallel_processes).to_i
parallel_processes = nil if parallel_processes == -1
Helpers.generate_icon(
icon_path: nil,
output_folder: xcasset_folder,
types: types,
parallel_processes: parallel_processes,
generate_icon: lambda do |_base_path, target_path, width, height|
system(
'magick',
'-size',
"#{width}x#{height}",
"xc:#{options.fetch(:background_color)}",
'-strokewidth',
(options.fetch(:stroke_width_offset).to_f * [width, height].min).to_s,
'-stroke',
(options.fetch(:stroke_width_offset).to_f.zero? ? 'none' : options.fetch(:stroke_color)).to_s,
'-fill',
options.fetch(:symbol_color),
'-gravity',
'center',
'-font',
options.fetch(:font),
'-pointsize',
(height * options.fetch(:size_offset).to_f).to_s,
'-annotate',
"+#{width * options.fetch(:x_offset).to_f}+#{height * -options.fetch(:y_offset).to_f}",
text,
target_path
)
end,
progress: lambda do |progress, total|
progress_bar.total = total unless progress_bar.total
progress_bar.increment if progress
end
)
puts "\nCompleted!".green
end
|