Skip to content

Instantly share code, notes, and snippets.

@the-teacher
Last active December 21, 2015 13:09
Show Gist options
  • Save the-teacher/6310984 to your computer and use it in GitHub Desktop.
Save the-teacher/6310984 to your computer and use it in GitHub Desktop.
Trim PNG files
require 'fileutils'
ROOT_PATH = File.dirname File.absolute_path(__FILE__)
src_dir = ROOT_PATH + "/src"
dest_dir = ROOT_PATH + "/dest"
src_dirs = Dir.glob(src_dir + '/*').select{|f| File.directory? f }
src_dirs.each do |dir|
dir_name = dir.split('/').last
dest_folder = [dest_dir, dir_name].join('/')
FileUtils.mkdir_p dest_folder
Dir.glob(dir + '/*.{png,PNG}').each do |src_file|
fname = File.basename src_file
dest_file = [dest_folder, fname].join '/'
`convert #{src_file} -trim #{dest_file}`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment