Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created November 21, 2010 08:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitode909/708578 to your computer and use it in GitHub Desktop.
Save hitode909/708578 to your computer and use it in GitHub Desktop.
画像をKindle用にトリミング,リサイズ,ガンマ調整
#!/usr/bin/env ruby
def suffix(file, suffix)
base = File.basename(file, File.extname(file))
ext = File.extname(file)
"#{base}#{suffix}#{ext}"
end
banner = <<EOF
usage
trimming_for_kindle.rb *.jpg
EOF
if ARGV.empty?
puts banner
exit(1)
end
ARGV.each{|file|
puts file
info = `identify #{file}`
size = info.scan(/\d+(?:x)\d+/).first
w, h = *size.split(/x/)
w = w.to_i
h = h.to_i
system "mogrify -crop #{w-40}x#{h-40}+20+20 #{file}" or exit
system "mogrify -fuzz 15% -trim #{file}" or exit
system "mogrify -gamma 0.3 -resize 560x742 #{file}" or exit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment