Created
July 31, 2012 01:44
-
-
Save Denommus/3212650 to your computer and use it in GitHub Desktop.
Checks all JPEG's in a given folder and creates thumbnails for them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'RMagick' | |
include Magick | |
dir = ARGV[0].dup | |
dir << '/' unless dir.match(/\/$/) | |
thumbnails = Dir.pwd+"/"+dir+"thumbnails" | |
Dir.chdir(Dir.pwd+"/"+dir) | |
puts Dir.pwd | |
puts thumbnails | |
Dir.mkdir(thumbnails) unless File.exists?(thumbnails) && File.directory?(thumbnails) | |
Dir['*.jpg'].each do |name| | |
puts name | |
f = open(name) | |
img = Image.from_blob(f.read).first | |
f2 = open(thumbnails+"/"+name, "w") | |
thumb = img.scale(ARGV[1].to_f/img.columns) | |
f2.puts(thumb.to_blob) | |
f.close | |
f2.close | |
puts name | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment