require "FileUtils"
require "ftools"
filetype = ".jpg"
path_in = Dir.pwd
path_out=path_in+"/thumbnail"
if !FileTest::directory?(path_out)
Dir::mkdir(path_out)
end
dir=Dir.open(path_in)
a=Array.new(dir.collect.length)
num=0
dir.each do |file|
if(file.length>filetype.length)
if (file[file.length-4..file.length]==filetype)
a[num]=file
num=num+1
end
end
end
puts num
for i in 0..num-1
fold = path_in + "/" + a[i]
fnew_ppm = path_out + "/" + a[i][0..a[i].length-5]+".ppm"
fnew_jpg = path_out + "/" + a[i][0..a[i].length-5]+".jpg"
cmdline="convert -resize 200x -quality 100 "+fold+" "+fnew_ppm
puts cmdline
system("#{cmdline}")
cmdline="convert -quality 100 "+fnew_ppm+" "+fnew_jpg
puts cmdline
system("#{cmdline}")
puts "---------------------"
File.delete(fnew_ppm)
end
Wednesday, December 2, 2009
[Ruby] make thumbnails
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment