Skip to content

Instantly share code, notes, and snippets.

@nhr
Created December 22, 2016 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhr/530cc0182825f21414fd233765ece050 to your computer and use it in GitHub Desktop.
Save nhr/530cc0182825f21414fd233765ece050 to your computer and use it in GitHub Desktop.
This script is useful for rotating & scaling images to a specific native resolution. I wrote it to prep pictures for use with a digital photo frame. I found that it is very hard to automate good cropping, but having everything at the same scale saves a lot of the work.
#!/usr/bin/env ruby
require 'fastimage'
FWIDTH = 1024
FHEIGHT = 600
workdir = Dir.pwd
Dir.foreach(workdir) { |item|
curritem = File.join(workdir,item)
pre = FastImage.size(curritem)
puts "- #{item} (#{pre[0]}x#{pre[1]})"
system("mogrify -auto-orient -resize \"#{FWIDTH}x#{FHEIGHT}^\" #{curritem}")
}
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment