Skip to content

Instantly share code, notes, and snippets.

@knowtheory
Created November 17, 2013 01:11
Show Gist options
  • Save knowtheory/7507667 to your computer and use it in GitHub Desktop.
Save knowtheory/7507667 to your computer and use it in GitHub Desktop.
require 'graphicsmagick'
size_strings = %w(
120x240
120x60
120x600
120x90
125x125
160x600
180x150
234x60
240x400
250x250
300x100
300x250
300x600
336x280
468x60
720x300
728x90
88x15
88x31
)
sizes = Hash[size_strings.map do |str|
width, height = str.split('x').map{ |number_string| number_string.to_i }
[width.to_f / height, [width, height]]
end]
files = ARGV
puts files.inspect
files.each_with_index do |img_path, index|
img = GraphicsMagick::Image.new img_path
img_ratio = img.width.to_f / img.height
ratios = sizes.keys.sort
crop_size = sizes[ratios.select{ |r| r < img_ratio }.sort.last]
`gm convert -scale #{crop_size.join('x')} #{img_path} #{index+1}artbanner#{crop_size.join('x')}.jpg`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment