Last active
December 21, 2015 13:09
-
-
Save the-teacher/6310984 to your computer and use it in GitHub Desktop.
Trim PNG files
This file contains hidden or 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
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