Screenshot of a particular area with Ruby and Puppeteer
Install Puppeteer and Grover
npm i puppeteer
gem install grover
Configure Grover
require 'grover'
Grover.configure do |config|
config.options = {
clip: {
x: 300,
y: 300,
width: 480,
height: 240
},
}
end
Take a screenshot of the clip and save to file
File.open("clip.png", "wb") do |f|
f.write(Grover.new('https://www.bbc.co.uk/news/business-63709754').to_png)
end
Find out how to take a full-page screenshot with Ruby and Puppeteer.
We created Urlbox to make converting HTML to images easy
Learn more about our website screenshot API.