
Untitled
By: a guest on
May 12th, 2012 | syntax:
None | size: 0.65 KB | hits: 15 | expires: Never
#!/usr/bin/env ruby
require "fileutils"
(puts "Usage: #{File.basename $0} widthxheight"; exit 0) if ARGV.size != 1
width, height = ARGV[0].split("x").collect(&:to_i)
(puts "Please enter a valid size."; exit 0) if ((width.to_i == 0) or (height.to_i == 0))
half_width = width / 2
FileUtils.cd("images") do
Dir['**/*'].each do |f|
next if f == "split_image.rb"
puts "Done processing #{f}."
name = File.basename(f).split('.')[0]
system("convert -crop #{half_width}x#{height}+0+0 #{name}.jpeg #{name}-1.jpg")
system("convert -crop #{half_width}x#{height}+#{half_width}+0 #{name}.jpeg #{name}-2.jpg")
system("mv #{name}.jpeg ../images2")
end
end