Skip to content

Web service that turns a web page into an image

License

Notifications You must be signed in to change notification settings

mkmiller/portrait

 
 

Repository files navigation

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 billing scheme with tiers, a customer and a user. Make sure you’re an admin

>> lower_tier = UsageTier.create start: 0, price_per: 0.05
=> #<UsageTier id: 1, start: 0, price_per: 0.05...
>> upper_tier = UsageTier.create start: 100, price_per: 0.02
=> #<UsageTier id: 2, start: 100, price_per: 0.02,
>> billing_scheme = BillingScheme.create name: 'Basic', usage_tiers: [lower_tier, upper_tier]
=> #<BillingScheme id: 3, name: "Basic"...

>> customer = Customer.create name: 'customer', billing_scheme: billing_scheme
=> #<Customer id: 1, name: "customer", canceled_at: nil...

>> User.create name: 'name', password: 'password', admin: true, customer: customer
=> #<User id: 1, name: "name", password: "password", admin: true, customer_id: 1...

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:[email protected]

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

About

Web service that turns a web page into an image

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 63.3%
  • Python 25.8%
  • HTML 8.1%
  • CSS 2.2%
  • JavaScript 0.6%