Creating screenshots with nanoc command
I just created a cool nanoc command that i would like to share with the world. It’s a nanoc command that goes to a URL, fetches all the links, does some simple sorting on these links, and then generates screenshot, with yaml metadata, for usage in a portfolio site, built in nanoc.
The script uses the selenium-webdriver to fire up a chrome or firefox session and click and shoot until it runs out of links, or it reaches the limit that you give on the command line. It saves the files in a folder of your choosing.
I made this, because I got tired of having to take screenshots of all the sites I worked on. “It can be done automatically”, the geek in me said!
First of start off by adding the selenium-webdriver gem to your project. You should use a Gemfile for managing gems in your project.
Make a Gemfile if you haven’t already in the root of your project:
Add the nanoc gem and the selenium-webdriver gem
gem 'nanoc' gem 'selenium-webdriver'
To let the selenium webdriver control your browser you should also install chromedriver if you’re using chrome. Firefox will run without any modification. I am on a mac by the way, and I won’t try to be clever about how this works on a pc.
brew install chromedriver
commands folder in your project root, and drop this code in
You can now run the command from the command-line. It takes three arguments (seperated by spaces): the url, the destination folder for the images, and how many max_items you want:
nanoc make_screenshots http://icanhas.cheezburger.com/ content/test 10
This should put 10 screen shots of funny cats in the folder content/test. It also creates the metadata yaml files, so you can add metadata to the images.
The files are named:
- … etc.
Have fun using this script. I hope you find it useful.