Created
April 11, 2011 09:31
-
-
Save peritus/913289 to your computer and use it in GitHub Desktop.
MOOCROP - Creates detail views of high-resolution photos suitable for creating moocards
This file contains hidden or 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 | |
# MOOCROP | |
# | |
# Results: http://ueberredungskunst.aadabay.com/moo-minicards | |
# | |
# Creates detail views of high-resolution photos suitable for creating moocards | |
# Slices in variations of top-left corner and scale | |
# | |
# Results after first order (used http://aadabay.com/ paintings: WOW!) | |
MINICARDS = 874, 378 | |
BUSINESSCARDS = 1039, 697 | |
EASES = [0.1, 0.2, 0.25, 0.3, 0.4, 0.5, 0.75, 1.0] | |
if ARGV.length < 2: | |
puts 'Usage: moocrop.rb times file [file ...]' | |
exit 1 | |
end | |
def moocrop(count) | |
imgfile = ARGV[count % ARGV.length] | |
moowidth, mooheight = MINICARDS | |
width, height = `identify #{imgfile}`.split()[2].split("x") | |
ease = EASES[rand(EASES.length)] | |
targetwidth = moowidth + (Integer(rand(Integer(width)-moowidth) * ease)) | |
targetheight = Integer(mooheight * (targetwidth / Float(moowidth))) | |
startwith = rand(Integer(width)-targetwidth) | |
startheight = rand(Integer(height)-targetheight) | |
basename = File.basename(imgfile, File.extname(imgfile)) | |
cmdline = ( | |
"convert #{imgfile} -crop " + | |
"#{targetwidth}x#{targetheight}+#{startwith}+#{startheight} " + | |
"-resize #{moowidth}x#{mooheight} " + | |
"moocrop-#{basename}-#{startwith}-#{startheight}.png" | |
) | |
puts cmdline | |
system cmdline | |
end | |
count = 0 | |
Integer(ARGV.shift).times { | |
count += 1 | |
moocrop count | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment