bin/image_voodoo in image_voodoo-0.8.7 vs bin/image_voodoo in image_voodoo-0.8.8

- old
+ new

@@ -1,9 +1,10 @@ #!/usr/bin/env ruby require 'optparse' +headless = true actions = [] images = [] original_image = nil opts = OptionParser.new do |opts| @@ -57,18 +58,37 @@ opts.on("-h", "--flip_horizontally") do actions << lambda {|img| img.flip_horizontally } end + opts.on("-m", "--metadata") do + actions << lambda {|img| puts img.metadata } + end + opts.on("-n", "--negative", "Make a negative out of the image") do actions << lambda {|img| img.negative } end + opts.on("-o", "--orient", "Rotate image to orient it based on metadata") do + actions << lambda {|img| img.correct_orientation } + end + opts.on("-q", "--quality 0..1", Float, "Set % of quality for lossy compression") do |quality| actions << lambda {|img| img.quality(quality) } end + opts.on("-R", "--rotate 0..360", Float, "Set angle to rotate image") do |angle| + actions << lambda {|img| img.rotate(angle.to_f) } + end + + opts.on("-r", "--resize WIDTHxHEIGHT", "Create a new image with the specified", "dimensions") do |dim| + width, height = dim.split(/x/i).map {|v| v.to_i} + opts.usage "You need to specify proper dimensions" unless width && width > 0 && height && height > 0 + actions << lambda {|img| img.resize(width,height) } + end + + opts.on("-s", "--save FILENAME", "Save the results to a new file") do |f| actions << lambda {|img| img.save(f); img } end opts.on("-t", "--thumbnail SIZE", Integer, "Create a thumbnail of the given size") do |size| @@ -79,10 +99,12 @@ actions << lambda {|img| img.flip_vertically } end opts.on("-p", "--preview", "Preview the image. Close the frame window", "to continue, or quit the application to", "abort the action pipeline") do + + headless = false actions << lambda do |img| done = false img.preview { done = true } Thread.pass until done img @@ -95,16 +117,10 @@ opts.on("--pop", "Revert back to the previous saved image", "or the original source image") do actions << lambda {|img| images.pop || original_image } end - opts.on("-r", "--resize WIDTHxHEIGHT", "Create a new image with the specified", "dimensions") do |dim| - width, height = dim.split(/x/i).map {|v| v.to_i} - opts.usage "You need to specify proper dimensions" unless width && width > 0 && height && height > 0 - actions << lambda {|img| img.resize(width,height) } - end - opts.on("-f", "--format", "Print the image format") do actions << lambda {|img| puts img.format; img } end opts.on_tail("-h", "--help", "Show this message") do @@ -119,9 +135,13 @@ end end opts.parse!(ARGV) opts.usage("You need to supply a source image filename.") unless ARGV.first opts.usage("You need to supply one or more actions.") unless actions.size > 0 + +# For this binstub we only want to load non-headless if we are using +# the preview feature. top of See lib/image_voodoo.rb for more info... +class ImageVoodoo; NEEDS_HEAD = true; end unless headless require 'image_voodoo' file_name = ARGV.first method = file_name =~ /^http:/ ? :from_url : :with_image ImageVoodoo.send(method, file_name) do |img|