-
-
Save rashivkp/ccdd72dc1f284043521f7b4766cc2575 to your computer and use it in GitHub Desktop.
Split a image into two halves.
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 "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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment