#!/usr/bin/env ruby require 'optparse' # Makes display figures based on the full-size figures. # The idea is to avoid throwing away data by storing full-size figures, # but resize them to a size appropriate for use in the document. options = {} OptionParser.new do |opts| opts.banner = "Usage: rename_screenshot [options]" opts.on("-a", "Regenerate all figures from full-size images") do options[:all] = true end opts.on("-w", "Resize to given width (in pixels)") do |width| options[:width] = width end end.parse! width = (options[:width] || "700") + '\>' target_dir = "images/figures" Dir.glob('full_size_figures/*').each do |full_size_filename| if full_size_filename =~ /(\w+)-full\.(.*)/ # Needed for backwards compatibility. filename = "#{target_dir}/#{$1}.#{$2}" else filename = "#{target_dir}/#{File.basename(full_size_filename)}" end unless File.exist?(filename) && !options[:all] cmd = "convert #{full_size_filename} -resize #{width} #{filename}" system cmd end end system "git add -A"