Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 12th, 2012  |  syntax: None  |  size: 0.65 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env ruby
  2. require "fileutils"
  3.  
  4. (puts "Usage: #{File.basename $0} widthxheight"; exit 0) if ARGV.size != 1
  5. width, height = ARGV[0].split("x").collect(&:to_i)
  6. (puts "Please enter a valid size."; exit 0) if ((width.to_i == 0) or (height.to_i == 0))
  7. half_width = width / 2
  8.  
  9. FileUtils.cd("images") do
  10.   Dir['**/*'].each do |f|
  11.     next if f == "split_image.rb"
  12.     puts "Done processing #{f}."
  13.     name = File.basename(f).split('.')[0]
  14.     system("convert -crop #{half_width}x#{height}+0+0 #{name}.jpeg #{name}-1.jpg")
  15.     system("convert -crop #{half_width}x#{height}+#{half_width}+0 #{name}.jpeg #{name}-2.jpg")
  16.     system("mv #{name}.jpeg ../images2")
  17.   end
  18. end