Created
August 31, 2013 04:14
-
-
Save kfriend/6396190 to your computer and use it in GitHub Desktop.
Ruby: Create image thumbnails using OS X sips
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
thumb_width = 117 | |
thumb_height = 141 | |
raise ArgumentError, 'No images given. You must supply at least one image to process' if ARGV.empty? | |
ARGV.each do |image| | |
if File.file?(image) | |
width = `sips -g pixelWidth "#{image}"`.match(/pixelWidth: \d+$/im).to_s.match(/\d+/).to_s.to_i | |
height = `sips -g pixelHeight "#{image}"`.match(/pixelHeight: \d+$/im).to_s.match(/\d+/).to_s.to_i | |
if width > height | |
target = height | |
else | |
target = width | |
end | |
`sips -c #{target} #{target} "#{image}"` | |
`sips -z #{thumb_height} #{thumb_width} "#{image}"` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment