Portrait is a web service which converts a website into a image. It is designed only for OS X. The actual hard work is handled by Paul Hammond’s webkit2png (available on GitHub). Portrait is primarily designed to be used as a web service, but does have a minimal admin interface.
Portrait is a Rails 4 application. So you’ll need some kind of Rails stack. Since it only runs on OS X, your best bet is to just use the included Apache install along with Passenger.
After you checkout the project from GitHub, you’ll need to configure database.yml
An example file is provided.
I’d suggest installing portrait on it’s own subdomain like portrait.mydomain.com. The API endpoint is the root of the URL, so that’ll make everything nice and easy.
Use whatever database you want, but it’ll work fine with SQLite. Begin by installing dependencies with bunder:
$ bundle
Create your first user with the console
$ rails console
Once in the console, create a user. Make sure you’re an admin
>> User.create name: 'name', password: 'password', admin: true => #<User id: 1, name: "name", password: "password", admin: true...
And that’s pretty much it. If you’re planning to run portrait on a server-type setup, keep in mind you need a user to be logged in for webkit2png to work.
Send a POST request to the root of the server (i.e. - portrait.mydomain.com). Use basic http authorization and provide a parameter named ‘url’. You can test it with curl:
curl -X POST -d "url=http://google.com" http://name:password@portrait.mydomain.com
On a valid url, you’ll get an XML response like this:
<site> <state>success</success> <image_url>sites/1/original/1-full.png</image_url> </site>
On an invalid url, you’ll get something like this:
<?xml version="1.0" encoding="UTF-8"?> <errors> <error>Url is invalid</error> </errors>
If you’re using Portrait within a Ruby project, you can use portrait_party to simplify the API calls. It’s a simple wrapper around John Nunemaker’s HTTParty.
Rather than open the service to the public, I opened up the source. I decided to go with basic user authentication just to be safe. I know it’s not the most secure thing ever, but that’s not really the point.
If you’re an admin user, you can login to /sites and /users to get an idea of what’s going on. You can also add new sites and users there.
-
portrait was created by Jordan McKible jordan.mckible.com
-
Available on GitHub github.com/jmckible/portrait
-
webkit2png by Paul Hammond www.paulhammond.org/webkit2png