Skip to content

Instantly share code, notes, and snippets.

@imonyse
Created October 22, 2011 15:46
Show Gist options
  • Save imonyse/1306127 to your computer and use it in GitHub Desktop.
Save imonyse/1306127 to your computer and use it in GitHub Desktop.
Ruby script helps me convert paperclip handled file to 48x48 size, running under the avatars root directory.
#!/usr/bin/env ruby
require 'fileutils'
def ignored_dir(name)
if name == '.' or name == '..'
return true
else
return false
end
end
Dir.foreach('.') do |d|
next if ignored_dir(d)
if File.directory? d
medium_dir = "#{d}/medium"
if !File.exists? medium_dir
FileUtils.mkdir medium_dir
end
original_dir = "#{d}/original"
Dir.foreach(original_dir) do |s|
next if ignored_dir(s)
`convert #{original_dir}/#{s} -resize 48x48 #{medium_dir}/#{s}`
puts "convert #{original_dir}/#{s} -resize 48x48 #{medium_dir}/#{s}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment