Sha256: 3c1406191c1c1ee87d0c9e1f5753fc82af60e0e83791afcc9f3ae1840e02daf3
Contents?: true
Size: 1.79 KB
Versions: 3
Compression:
Stored size: 1.79 KB
Contents
#!/usr/bin/env ruby require 'optparse' lib = File.expand_path(File.dirname(__FILE__) + '/../lib') $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib) require 'rmagick/screwdrivers' # options = { # :widths => 600, # :date_in_watermark => false, # :watermark => nil, # :logger => nil # }.merge(options) options = {} OptionParser.new do |opts| opts.banner = "Usage: #{$0} [options] FILE [DIR]" # Verbose? opts.on("-v", "--verbose", "Run verbosely (default: false)") do |v| if v require 'logger' options[:logger] = Logger.new STDOUT end end # Quality opts.on("-q", "--quality [1-100]", Integer, "Quality of resulting JPEG (default: 90)") do |quality| options[:quality] = quality end # Widths opts.on("-w", "--widths X,Y,Z", Array, "Widths of scaled images (default: 600)") do |widths| options[:widths] = widths.map(&:to_i) - [0] end # Puts date on watermark? opts.on("-d", "--date_in_watermark", "Append date to watermark (default: false)") do |dow| options[:date_in_watermark] = dow end # Watermark text opts.on("-m", "--watermark TEXT", "Text to use as watermark (default: none)") do |w| options[:watermark] = w end # No argument, shows at tail. This will print an options summary. opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end.parse! raise "Run `#{$0} --help` for execution examples. Exiting…" if ARGV.size.zero? || ARGV.size > 2 file = ARGV.first dir = ARGV.size == 2 ? ARGV.last : File.dirname(file) `mkdir -p #{dir}` Magick::Screwdrivers::scale(file, options).each { |img| outfile = File.basename(file).sub(/(\.\w+)$/, "-#{img.rows}×#{img.columns}\\1") img.write(File.join dir, outfile) { self.quality = options[:quality] || 90 } }
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rmagick-screwdrivers-0.2.0 | bin/magick_scale |
rmagick-screwdrivers-0.1.2 | bin/magick_scale |
rmagick-screwdrivers-0.1.1 | bin/magick_scale |