Created
June 13, 2012 06:47
-
-
Save yasuoza/2922393 to your computer and use it in GitHub Desktop.
Convert normal image name to retina image name
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
#!env ruby | |
require 'rubygems' | |
require 'fileutils' | |
images_dir = ARGV[0] | |
if images_dir == nil | |
puts "Error! Input images directory" | |
exit | |
end | |
if !FileTest.exist?(images_dir) | |
puts "Error! There is no such directory #{images_dir}" | |
exit | |
end | |
def image_renamer(arg_dir) | |
images = []; | |
Dir.entries(arg_dir).each do |filename| | |
# Do recursively | |
if FileTest.directory?(arg_dir + "/" + filename) | |
next if /\.+/ =~ filename | |
image_renamer(arg_dir + "/" + filename) | |
end | |
img_type = File.extname(filename).downcase | |
if (img_type == '.png' || img_type == '.jpg' || img_type == '.tif') | |
ext = File.extname(filename) | |
basename = File.basename(filename, ext) | |
dir = File.dirname(filename) | |
next if /(.+)@2x(#{ext})$/ =~ filename | |
export_dir = "./2x_#{arg_dir}" | |
if !FileTest.exist?("export_dir") | |
FileUtils.mkdir_p(export_dir) | |
end | |
FileUtils.cp("#{arg_dir}/#{basename}#{img_type}", "#{export_dir}/#{basename}@2x#{img_type}") | |
end | |
end | |
end | |
image_renamer(ARGV[0]) | |
puts "Renamed normal images to retina images" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment