Over a million developers have joined DZone.

Screenshots - Ruby

DZone's Guide to

Screenshots - Ruby

Free Resource
Requires - Win32Screenshot Or RMagick
You can uncomment corresponding code if using RMagick. This script is ready to take screenshots on a Win32 System. Users can opt to use RMagick on //other Platforms. (Considering RMagick installation over Win32 platform is complicated).

require 'win32screenshot'
#require 'RMagick'
t = Time.now
str = t.strftime("%Y%m%d_%H%M%S")
# Take Foreground Screenshot
# width, height, bmp = Win32::Screenshot.foreground
# Take Desktop Screenshot

width, height, bmp = Win32::Screenshot.desktop

# Take Application Window Screenshot
# width, height, bmp = Win32::Screenshot.window(/Firefox/)
img_path = ARGV[0] || "file_#{str}.bmp"

File.open(img_path, "wb") {  |io| 
# img = Magick::Image.from_blob(bmp)[0]
# dir and spec number are defined outside
# img_path = img_path + ".png" 
# img.write(img_path)

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}