From 2e5ad9135530a2bd5d9b2730471b2e43b99cab0f Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Wed, 17 Nov 2021 07:24:47 -0600 Subject: Script for generating screenshots --- scripts/screenshot.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 scripts/screenshot.rb (limited to 'scripts') diff --git a/scripts/screenshot.rb b/scripts/screenshot.rb new file mode 100644 index 0000000..fa6ad1f --- /dev/null +++ b/scripts/screenshot.rb @@ -0,0 +1,47 @@ +# Script that uses the ferrum gem to generate screenshots from a headless browser + +require 'ferrum' +require 'optparse' + +options = {show_help: false, out: "out.png"} + +opts = OptionParser.new do |o| + o.banner = "Usage: #{File.basename($0)} [options]\n\n" + o.on("--url str","-u", "Fetch URL") do |url| + options[:url] = url + end + o.on("--out str","-o", "Output file") do |out| + options[:out] = out + end + o.on("--extract str", "Extract dimensions") do |dim| + options[:extract] = dim + end + + o.on_tail('-h', '--help', 'Display this help and exit') do + options[:show_help] = true + end +end +begin + opts.parse!(ARGV) + + if options[:show_help] + print opts + print USAGE + exit 0 + end + +rescue OptionParser::InvalidOption => e + options[:invalid_argument] = e.message +end + +print("\nProcessing #{options[:url]}...") +browser = Ferrum::Browser.new +browser.timeout = 20 +browser.go_to(options[:url]) +browser.screenshot(path: options[:out]) +browser.quit + +if options[:extract] + print `convert -extract #{options[:extract]} #{options[:out]} convert.png` + File.rename("convert.png",options[:out]) +end -- cgit v1.2.3