Check a directory for transparent pngs recursively
This requires that you have ImageMagick installed on whatever machine you run it on as the `identify -format %A file.png` bit is actually a shell command for ImageMagick. Ruby just was easier for me to figure out how to recursively run that on all .png files in a given directory. I’m sure there is a shorter shell script to do the same thing. The script will probably run without ImageMagick installed, but it most likely won’t give any output.
View as text
require 'find'
def find_and_print(path, pattern)
Find.find(path) do |entry|
if File.file?(entry) and entry[pattern]
has_transparency = `identify -format %A #{entry}`
if has_transparency.to_s.chomp.strip == "True"
puts "#{entry}"
end
end
end
end
# print all the ruby files
find_and_print("/rails_app/public/images", /.+\.png$/)