public
Description: Web service that turns a web page into an image
Homepage: http://jordan.mckible.com
Clone URL: git://github.com/jmckible/portrait.git
jmckible (author)
Mon Aug 31 20:52:56 -0700 2009
commit  7bb9e27627a8e6f814a6936848cfddb8d52963b2
tree    adc83fb3d15259beacc358b2020d87efe8602378
parent  ed70dc098b29187f6cba90847bd1791791d5db99
name age message
file .gitignore Fri Jun 19 13:11:05 -0700 2009 Configure Site with paperclip. [jmckible]
file MIT-LICENSE Loading commit data...
file README.rdoc
file Rakefile Wed Jun 17 16:16:32 -0700 2009 Empty Rails 2.3.2 template. [jmckible]
directory app/
directory config/
directory db/
directory doc/
directory lib/ Sun Jun 21 14:46:39 -0700 2009 Configure rspec. [jmckible]
directory public/
directory script/ Sun Jun 21 14:46:39 -0700 2009 Configure rspec. [jmckible]
directory spec/
directory vendor/
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 2.3+ 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. Note: the session variables session_key and secret are configured in this file as well. (In a normal Rails project these would be configured elsewhere, but since this is open source, everyone needs their own key/secret)

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.

Create your first user with the console

  $ script/console

Note: If you’re setting this up for production, make sure you set your Rails environment variable to ‘production’ or force it in the console

  $ script/console production

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

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