Posted in Knowledge
Tags: screenshot
How can our code take a screenshot of a webpage, and save it to an image file ?
It turns out it’s easy. First, we need to
gem install win32screenshot
Then, write code something like this:
require ‘win32screenshot’
width, height, bmp = Win32::Screenshot.foreground
img = Magick::Image.from_blog(bmp)[0]
img.write(RAILS_ROOT + “/public/images/screenshot.png”)
Voila, and you get the screenshot!
A couple of fixes:
require ‘rubygems’
require ‘win32screenshot’
require ‘RMagick’
include Magick
width, height, bmp = Win32::Screenshot.foreground
img = Magick::Image.from_blob(bmp)[0]
img.write(”./screenshot.png”)
btw..you misspelled blob with blog in your post, so you’re calling a funciont that doesn’t exist:
from_blob. My “couple of fixes” works correctly.
My bad. Thanks.