bin/image_voodoo in image_voodoo-0.1 vs bin/image_voodoo in image_voodoo-0.2

- old
+ new

@@ -25,20 +25,34 @@ opts.separator " --pop --resize 30x30 --dim --preview --save t3.jpg image.jpg" opts.separator "" opts.separator "Actions:" + opts.on("-b", "--brightness SCALE,OFFSET", "Adjust brightness") do |args| + scale, offset = args.split(/\,/i).map {|v| v.to_f} + opts.usage "You need to specify proper scale and offset" unless scale && offset + actions << lambda {|img| img.adjust_brightness(scale, offset) } + end + opts.on("-d", "--dimensions", "Print the image dimensions") do actions << lambda {|img| puts "#{img.width}x#{img.height}"; img } end + opts.on("-g", "--greyscale", "Convert image to greyscale") do + actions << lambda {|img| img.greyscale } + end + + opts.on("-n", "--negative", "Make a negative out of the image") do + actions << lambda {|img| img.negative } + 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| - actions << lambda {|img| result = nil; img.thumbnail(size) {|img2| result = img2 }; result } + actions << lambda {|img| img.thumbnail(size) } end opts.on("-p", "--preview", "Preview the image. Close the frame window", "to continue, or quit the application to", "abort the action pipeline") do actions << lambda do |img| @@ -58,11 +72,11 @@ 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| result = nil; img.resize(width,height) {|img2| result = img2}; result } + actions << lambda {|img| img.resize(width,height) } end opts.on_tail("-h", "--help", "Show this message") do puts opts exit 0 @@ -77,13 +91,13 @@ 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 require 'image_voodoo' -ImageVoodoo.with_image(ARGV.first) do |img| +file_name = ARGV.first +method = file_name =~ /^http:/ ? :from_url : :with_image +ImageVoodoo.send(method, file_name) do |img| original_image = img - actions.each do |act| - img = act.call(img) - end + actions.each { |act| img = act.call(img) } end # Be sure we exit out of swing java.lang.System.exit(0)