Skip to content

Instantly share code, notes, and snippets.

@chengbo
Forked from uberbruns/testassets.rb
Created September 11, 2016 06:02
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 chengbo/db93d539416fe29e19a731e25cb9e94a to your computer and use it in GitHub Desktop.
Save chengbo/db93d539416fe29e19a731e25cb9e94a to your computer and use it in GitHub Desktop.
iOS Retina Assets Test
require 'fileutils'
path = ARGV[0]
ok = 0
fail = 0
Dir.glob("#{path}/*.png", File::FNM_DOTMATCH) do |f|
unless f.end_with? "@2x.png" or f.end_with? "@3x.png"
s2_f = File.basename(f, ".png") + "@2x.png"
s3_f = File.basename(f, ".png") + "@3x.png"
s2_f = File.join(path, s2_f)
s3_f = File.join(path, s3_f)
if not File.exist?(s2_f)
puts "Missing File: #{s2_f}"
fail = fail + 1
elsif not File.exist?(s3_f)
puts "Missing File: #{s3_f}"
fail = fail + 1
else
s1_x, s1_y = IO.read(f)[0x10..0x18].unpack('NN')
s2_x, s2_y = IO.read(s2_f)[0x10..0x18].unpack('NN')
s3_x, s3_y = IO.read(s3_f)[0x10..0x18].unpack('NN')
is_ok = true
if s1_x*2 != s2_x || s1_y*2 != s2_y
puts "Bad Dimensions: #{s2_f}; Found: #{s2_x}x#{s2_y}; Expected: #{s1_x*2}x#{s1_y*2}"
fail = fail + 1
is_ok = false
end
if s1_x*3 != s3_x || s1_y*3 != s3_y
puts "Bad Dimensions: #{s3_f}; Found: #{s3_x}x#{s3_y}; Expected: #{s1_x*3}x#{s1_y*3}"
fail = fail + 1
is_ok = false
end
if is_ok
ok = ok + 1
end
end
end
end if File.directory?(path)
puts "OK: #{ok}; Fail: #{fail}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment