1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#!/usr/bin/ruby -ws
$s ||= false
abort "#{File.basename $0} max_length files..." unless ARGV.size > 1
require 'rubygems'
require 'image_science'
max_length = ARGV.shift.to_i
msg = $s ? :cropped_thumbnail : :thumbnail
ARGV.each do |file|
begin
result = ImageScience.with_image file do |img|
begin
img.send(msg, max_length) do |thumb|
# add _thumb and switch from gif to png. Really. gif just sucks.
out = file.sub(/(\.[^\.]+)$/, '_thumb\1').sub(/gif$/, 'png')
thumb.save(out)
end
rescue => e
warn "Exception thumbnailing #{file}: #{e}"
end
end
p file => result
rescue => e
warn "Exception opening #{file}: #{e}"
end
end
|