Skip to content

Instantly share code, notes, and snippets.

@patoroco
Last active December 27, 2015 19:14
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 patoroco/2774efff146c8cb02108 to your computer and use it in GitHub Desktop.
Save patoroco/2774efff146c8cb02108 to your computer and use it in GitHub Desktop.
Script to compare retina and non-retina images to test if there are correctly sized
#!/usr/bin/env ruby
require 'fastimage'
if ARGV.count != 1
puts "Use command: \n$ ruby #{__FILE__} <.xcassets>"
exit()
end
def test_if_retina_is_par file_path
size_array = FastImage.size(file_path)
width = size_array[0]
height = size_array[1]
if (width.to_i % 2) != 0 || (height.to_i % 2) != 0
puts "#{file_path} :: (#{width}, #{height})"
end
end
def find_coincidences(current_path, file_pattern)
Dir.foreach(current_path).each do |file|
next if file == "." || file == ".."
file_expanded = File.join current_path, file
if File.directory? file_expanded
find_coincidences file_expanded, file_pattern
next
end
if file_expanded.end_with? file_pattern
test_if_retina_is_par file_expanded
end
end
end
assets_path = File.expand_path(ARGV[0])
find_coincidences assets_path, "@2x.png"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment