Add a file name to images.(ImageMagick)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_files_from_ARGV(recursive: true) | |
files = ARGV.map do |path| | |
path = File.expand_path(path) | |
if File.directory?(path) | |
if recursive | |
Dir.glob(File.join(path, '**', '*')) | |
else | |
Dir.glob(File.join(path, '*')) | |
end | |
elsif File.file?(path) | |
path | |
else | |
puts("Not exists file: #{path}") | |
end | |
end | |
raise('ARGV empty') if ARGV.empty? | |
files.flatten.compact.sort.reject { |e| File.directory?(e) } | |
end | |
def add_file_name | |
font_path = '/System/Library/Fonts/Helvetica.ttc' | |
pointsize = '30' | |
get_files_from_ARGV.each do |file| | |
puts(file) | |
file_name = File.basename(file, '.*') | |
outfile = File.join(File.dirname(file), file_name + '-caption' + File.extname(file)) | |
cmd = ['convert', '-font', font_path, '-pointsize', pointsize, | |
'-gravity', 'south', '-annotate', '0' , file_name, file, outfile] | |
system(*cmd) | |
end | |
end | |
add_file_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment