Skip to content

Instantly share code, notes, and snippets.

@Coro365
Created March 28, 2020 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Coro365/f75e918337d22eba34f1bc5044fd6e2c to your computer and use it in GitHub Desktop.
Save Coro365/f75e918337d22eba34f1bc5044fd6e2c to your computer and use it in GitHub Desktop.
Add a file name to images.(ImageMagick)
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