Skip to content

Instantly share code, notes, and snippets.

@koyachi
Created July 29, 2010 02:04
Show Gist options
  • Save koyachi/497015 to your computer and use it in GitHub Desktop.
Save koyachi/497015 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'find'
require 'yaml'
module ImageMetaYamlGenerator
# via http://www.atmarkit.co.jp/flinux/rensai/linuxtips/294grainfo.html
def self.identify(image_file)
result = `identify #{image_file}`
list = result.split(/\s/)
w,h = list[2].split(/x/).map{|v| v.to_i}
return {
:filename => image_file,
:type => list[1],
:width => w,
:height => h,
:description => '',
}
end
def self.run(dir)
files = []
Find.find(dir) do |path|
if File.file?(path) && path =~ /\.(jpg|jpeg|gif)$/i
files.push identify(path)
end
end
yaml = YAML.dump(files, File.open("#{dir}/image_meta__template.yaml", "w"))
end
end
dir = File.expand_path(ARGV[0] || './kiva')
ImageMetaYamlGenerator.run dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment