lib/perus/pinger/metrics/screenshot.rb in perus-0.1.10 vs lib/perus/pinger/metrics/screenshot.rb in perus-0.1.11
- old
+ new
@@ -22,21 +22,31 @@
# sips helpfully prints data to stderr, so it's run with
# backticks to avoid thowing an exception on success
`sips -z #{height.to_i * percent} #{width.to_i * percent} #{options.path}`
else
- shell("export DISPLAY=:0; import -window root -resize #{options.resize} #{options.path}")
+ shell("export DISPLAY=:0; scrot --silent --thumb #{options.resize.to_i} #{options.path}")
end
- @screenshot_file = File.new(options.path)
+ # scrot produced two files: path.ext and path-thumb.ext
+ @original_path = options.path
+ name_parts = File.basename(options.path).split('.')
+ name_parts[-2] += '-thumb'
+ @thumbnail_path = File.join(
+ File.dirname(options.path),
+ name_parts.join('.')
+ )
+
+ @screenshot_file = File.new(@thumbnail_path)
{screenshot: @screenshot_file}
end
def cleanup
unless @screenshot_file.nil? || @screenshot_file.closed?
@screenshot_file.close
end
- File.delete(options.path)
+ File.delete(@original_path)
+ File.delete(@thumbnail_path)
end
end
end