aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPjotr Prins2021-11-17 07:24:47 -0600
committerPjotr Prins2021-11-17 07:24:47 -0600
commit2e5ad9135530a2bd5d9b2730471b2e43b99cab0f (patch)
treeb67649b338d974de235ccf5ff2d94d3d55d5b265
parentd16b07f612ff87791dc63f976e872301dc332fd0 (diff)
downloadgn-docs-2e5ad9135530a2bd5d9b2730471b2e43b99cab0f.tar.gz
Script for generating screenshots
-rw-r--r--scripts/screenshot.rb47
1 files changed, 47 insertions, 0 deletions
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