Skip to content

Instantly share code, notes, and snippets.

@luisparravicini
Created September 4, 2012 20:58
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 luisparravicini/3626371 to your computer and use it in GitHub Desktop.
Save luisparravicini/3626371 to your computer and use it in GitHub Desktop.
Combine image assets in different sizes (for iPhone/iPad) into a single directory using cocos2d sufixes
require 'fileutils'
include FileUtils
#
# Copy images from a directory hierarchy like this:
#
# dir/
# 320x480/
# 640x480/
# 1024x768/
# 2048x1536/
#
# to a single directory using cocos2d 2.x default sufixes for images ('', -hd, -ipad, -ipadhd).
#
$src_dir = ARGV.shift
$assets_dir = ARGV.shift
if $src_dir.nil? || $assets_dir.nil?
puts "usage: #{$0} <src_dir> <assets_dir>"
exit 1
end
def copy_assets(resolution, sufix)
dir = File.join($src_dir, resolution)
unless File.directory?(dir)
$stderr.puts "#{dir} doesn't exists"
return
end
sufix ||= ''
paths = Dir.glob(File.join(dir, '*'))
paths.each do |path|
ext = File.extname(path)
out_path = File.join($assets_dir, File.basename(path, ext) + sufix + ext)
cp(path, out_path)
end
puts "#{paths.size} files copied from #{resolution}"
end
resolutions = [
[ '320x480', nil ],
[ '640x960', '-hd' ],
[ '1024x768', '-ipad' ],
[ '2048x1536', '-ipadhd' ],
]
resolutions.each { |res| copy_assets(*res) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment