Web service that turns a web page into an image
Ruby Python HTML CSS JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
app
bin
config
db
lib
public
spec
vendor/assets
.gitignore
.rspec
.rubocop.yml
Gemfile
Gemfile.lock
MIT-LICENSE
README.rdoc
Rakefile
config.ru

README.rdoc

portrait

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.

Installation

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.

How it works

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=https://google.com" http://name:password@portrait.mydomain.com

On a valid url, you'll get an XML response like this:

<site>
  <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>

portrait_party

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.

Authorization

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.

Admin

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.

Author