Skip to content

Instantly share code, notes, and snippets.

@venj
Created June 9, 2012 06:02
Show Gist options
  • Save venj/2899708 to your computer and use it in GitHub Desktop.
Save venj/2899708 to your computer and use it in GitHub Desktop.
convert images to fixed width images
#!/usr/bin/env ruby
TARGET_WIDTH = 1000.0
Dir["*.jpg"].each do |f|
fileinfo = `convert #{f} -print "%wx%h" /dev/null`
width, height = fileinfo.split("x").collect(&:to_i)
height *= (TARGET_WIDTH / width)
width = TARGET_WIDTH
print "Processing #{f}..."
system("convert -resize #{width}x#{height} #{f} re_#{f}")
puts "done."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment