1 ************************************
2 phancap - website screenshot service
3 ************************************
5 Web service (API) to create website screenshots.
7 Self-hosted and written in PHP. Caching included.
10 *phancap* is useful for:
12 - Show screenshots for websites in your bookmarking application
13 - Archive a HTML page as PDF for later viewing
23 * Configurable browser size
24 * Configurable screenshot size
25 * Clip and full page rendering (full height)
26 * JPG, PNG and PDF output (PDFs are searchable)
28 * Can run on a normal web server without GUI. See dependencies_.
29 * Generated images get meta data embedded:
31 * URL of captured page
36 *phancap* does not rely on a "real" browser.
37 Currently ``cutycapt`` is utilized, which uses a pretty bare webkit to render
39 Do not expect pixel-for-pixel identical rendering as your desktop browser.
48 #. Download the ``.phar`` file and put it onto your web server
49 #. Open the phar file in your browser
51 If you only see text beginning with ``<?php``, you need to
52 `setup .phar file extension handling`__ in your web server first.
53 #. Click the "setup check" link
54 #. Fix all errors that are reported
55 #. Run ``phancap.phar/get.php?url=cweiske.de`` and see the screenshot
57 __ http://cweiske.de/tagebuch/phar-webserver.htm
62 With the basic setup, everyone may use your server to create website
64 You may want to change that or simply change some default settings.
66 #. Create a config file ``phancap.phar.config.php``
67 #. Edit it; see the configuration_ options.
73 ``get.php`` supports the following parameters:
80 Browser width (default: 1024)
82 Browser height (default: none)
87 Screenshot width (default: none (no scaling))
89 Screenshot height (default: none)
91 Screenshot format (``png``, ``jpg``, ``pdf``, default: ``png``)
93 Screenshot mode (``screen`` (4:3) or ``page`` (full website height))
95 Maximum age of screenshot in seconds.
96 ISO 8601 duration specifications accepted:
103 The configuration file defines a minimum age that the user cannot undercut
104 (``$screenshotMinAge``), as well as a default value (``$screenshotMaxAge``).
106 Authentication parameters
107 =========================
109 Time at which the request URL was generated (unix timestamp)
111 Access token (username)
113 Signature for the request. See the authentication_ section.
119 phancap looks at several places for its configuration file:
121 #. ``phancap.phar.config.php`` in the same directory as your
122 ``phancap.phar`` file.
124 #. ``/etc/phancap.php``
127 Configuration variables
128 =======================
130 Full file system path to image cache directory
132 Full URL to cache directory
134 Credentials for access control
136 ``true`` to allow access to anyone, ``false`` to disable it completely.
137 ``array`` of username - secret key combinations otherwise.
138 ``$cutycapt['parameters']``
139 Additional command line parameters for cutycapt.
140 Can be used to e.g. enable browser plugins:
142 ``$cutycapt['parameters'] = '--plugins=on';``
143 ``$cutycapt['maxWaitTime']``
144 Maximal time in seconds to wait for cutycapt to finish rendering.
145 Defaults to 30 seconds.
147 Disable ``setup.php`` which will leak file system paths
149 Redirect to static image urls after generating them
151 How long a signature timestamp is considered valid. 2 days default.
152 ``$screenshotMaxAge``
153 Cache time of downloaded screenshots.
155 When the file is as older than this, it gets re-created.
156 ``$screenshotMinAge``
157 Minimum age of a screeshot. 1 hour default.
159 A user cannot set the max age parameter below it.
166 Creating screenshots of websites is a resource intensive process.
167 To prevent unauthorized access to the service, phancap supports authentication
168 via a signature parameter similar to OAuth's ``oauth_signature``.
170 Phancap's configuration file may contain a ``$access`` variable:
173 Everyone is allowed to access the service
175 Nobody is allowed to access the service
177 A list of usernames that are allowed to request screenshots, together
178 with their secret keys (password)::
181 'user1' => 'secret1',
182 'user2' => 'secret2',
185 The signature algorithm is as follows:
187 #. Parameters ``atimestamp`` (current unix timestamp) and
188 ``atoken`` (username) have to be added to the URL parameters
190 #. URL parameters are normalized as described in
191 `OAuth Parameters Normalization`__:
193 #. Sort parameters list by name
194 #. Name and value are `raw-url-encoded`__
195 #. Name and value are concatenated with ``=`` as separator
196 #. The resulting strings are concatenated with ``&`` as separator
198 #. URL parameter string is used together with the secret key
199 to create a `HMAC-SHA1`__ digest
201 #. Digest is appended to the URL as ``asignature``
203 __ http://tools.ietf.org/html/rfc5849#section-3.4.1.3.2
204 __ http://tools.ietf.org/html/rfc5849#section-3.6
205 __ http://tools.ietf.org/html/rfc5849#section-3.4.2
213 The ``docs/`` directory contains an example PHP client implementation.
215 We want to create a screenshot of ``http://example.org/`` in size 400x300,
216 using the browser size of 1024x768::
218 http://example.org/phancap/get.php?swidth=400&sheight=300&url=http%3A%2F%2Fexample.org%2F&bwidth=1024&bheight=768
220 Phancap's config file contains::
226 Our parameters are thus:
233 ``url`` ``http://example.org/``
238 At first, we need to add parameters ``atimestamp`` and ``atoken``.
239 ``atimestamp`` is the current unix timestamp.
240 ``atoken`` is our user name: ``user``.
242 Now the parameter list is sorted:
247 ``atimestamp`` ``1396353987``
253 ``url`` ``http://example.org/``
256 The parameters are raw-url-encoded. The only value that changes is the url,
257 it becomes ``http%3A%2F%2Fexample.org%2F``.
259 Concatenating the name/value pairs leads to the following string::
261 atimestamp=1396353987&atoken=user&bheight=768&bwidth=1024&sheight=300&swidth=400&url=http%3A%2F%2Fexample.org%2F
263 Creating the HMAC digest with sha1, the calculated string and our key
264 ``secret`` gives us the following string::
266 9a12eac5ff859f9306eaaf5a18b9a931fe10b89d
268 This is the signature; it gets appended to the URL as ``asignature`` parameter.
276 - `cutycapt <http://cutycapt.sourceforge.net/>`_
277 - `exiftool <http://owl.phy.queensu.ca/~phil/exiftool/>`_
278 - `imagemagick's <http://www.imagemagick.org/>`_ ``convert``
281 - Libraries (already included in the ``.phar``):
283 - PEAR's ``System.php``
292 ``phancap`` is licensed under the `AGPL v3`__ or later.
294 __ http://www.gnu.org/licenses/agpl.html
300 http://cweiske.de/phancap.htm
303 http://git.cweiske.de/phancap.git
305 Mirror: https://github.com/cweiske/phancap
316 All of those are open source:
318 * http://code.google.com/p/browsershots/ (python)
319 * https://github.com/gre/screenshot-webservice (scala)
326 Releasing a new version
327 =======================
329 #. Update ``ChangeLog``
330 #. Change version number in ``build.xml``
332 #. Deploy the new files in ``dist/``
333 #. Tag the new version in git