ruby - RuntimeError when running script? -
so have found ruby script, looks png images in sub folders , folders , converts png images using tinypng api reason runtime error
c:/users/vygantas/desktop/tinypng.rb:14:in `': usage: ./tinypng.rb c:/users/vygantas/desktop/product c:/users/vygantas/desktop/product(runtimeerror)
#!/usr/bin/ruby -w # # tinypng.rb — placed public domain daniel reese. # require 'rubygems' require 'json' # set api key. apikey = "xxxxxxxxxxxxxxxx" # verify arguments. argv.length == 2 or fail("usage: ./tinypng.rb c:\users\vygantas\desktop\product c:\users\vygantas\desktop\product*emphasized text*") src = argv[0] dst = argv[1] file.exist?(src) or fail("input folder not exist: " + src) file.exist?(dst) or fail("output folder not exist: " + dst) # optimize each image in source folder. dir.chdir(src) dir.glob('*.png') |png_file| puts "\noptimizing #{png_file}" # optimize , deflate both images. cmd = "curl -u api:#{apikey} --data-binary @#{png_file} 'https://api.tinypng.com/shrink'" puts cmd r = json.parse `#{cmd}` if r['error'] puts "tinypng error: #{r['message']} (#{r['error']})" exit(1) end url = r['output']['url'] cmd = "curl '#{url}' -o #{dst}/#{png_file}" puts cmd `#{cmd}` end dir.chdir("..") puts 'done'
as might see in code, line 14 (as printed on script execution):
argv.length == 2 or fail("usage: ./tinypng.rb c:\...\product c:\...\product*emphasized text*")
that said, script requires 2 parameters run. let me guess: did not pass 2 parameters. btw source , destination folders.
Comments
Post a Comment