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_.
32 *phancap* does not rely on a "real" browser.
33 Currently ``cutycapt`` is utilized, which uses a pretty bare webkit to render
35 Do not expect pixel-for-pixel identical rendering as your desktop browser.
44 #. Download the ``.phar`` file and put it onto your web server
45 #. Open the phar file in your browser
46 #. Click the "setup check" link
47 #. Fix all errors that are reported
48 #. Run ``phancap.phar/get.php?url=cweiske.de`` and see the screenshot
53 With the basic setup, everyone may use your server to create website
55 You may want to change that or simply change some default settings.
57 #. Create a config file ``phancap.phar.config.php``
58 #. Edit it; see the configuration_ options.
64 ``get.php`` supports the following parameters:
71 Browser width (default: 1024)
73 Browser height (default: none)
78 Screenshot width (default: none (no scaling))
80 Screenshot height (default: none)
82 Screenshot format (``png``, ``jpg``, ``pdf``, default: ``png``)
84 Screenshot mode (``screen`` (4:3) or ``page`` (full website height))
86 Maximum age of screenshot in seconds.
87 ISO 8601 duration specifications accepted:
94 The configuration file defines a minimum age that the user cannot undercut
95 (``$screenshotMinAge``), as well as a default value (``$screenshotMaxAge``).
97 Authentication parameters
98 =========================
100 Time at which the request URL was generated (unix timestamp)
102 Access token (username)
104 Signature for the request. See the authentication_ section.
110 phancap looks at several places for its configuration file:
112 #. ``phancap.phar.config.php`` in the same directory as your
113 ``phancap.phar`` file.
115 #. ``/etc/phancap.php``
118 Configuration variables
119 =======================
121 Full file system path to image cache directory
123 Full URL to cache directory
125 Credentials for access control
127 ``true`` to allow access to anyone, ``false`` to disable it completely.
128 ``array`` of username - secret key combinations otherwise.
129 ``$cutycapt['parameters']``
130 Additional command line parameters for cutycapt.
131 Can be used to e.g. enable browser plugins:
133 ``$cutycapt['parameters'] = '--plugins=on';``
134 ``$cutycapt['maxWaitTime']``
135 Maximal time in seconds to wait for cutycapt to finish rendering.
136 Defaults to 30 seconds.
138 Disable ``setup.php`` which will leak file system paths
140 Redirect to static image urls after generating them
142 How long a signature timestamp is considered valid. 2 days default.
143 ``$screenshotMaxAge``
144 Cache time of downloaded screenshots.
146 When the file is as older than this, it gets re-created.
147 ``$screenshotMinAge``
148 Minimum age of a screeshot. 1 hour default.
150 A user cannot set the max age parameter below it.
157 Creating screenshots of websites is a resource intensive process.
158 To prevent unauthorized access to the service, phancap supports authentication
159 via a signature parameter similar to OAuth's ``oauth_signature``.
161 Phancap's configuration file may contain a ``$access`` variable:
164 Everyone is allowed to access the service
166 Nobody is allowed to access the service
168 A list of usernames that are allowed to request screenshots, together
169 with their secret keys (password)::
172 'user1' => 'secret1',
173 'user2' => 'secret2',
176 The signature algorithm is as follows:
178 #. Parameters ``atimestamp`` (current unix timestamp) and
179 ``atoken`` (username) have to be added to the URL parameters
181 #. URL parameters are normalized as described in
182 `OAuth Parameters Normalization`__:
184 #. Sort parameters list by name
185 #. Name and value are `raw-url-encoded`__
186 #. Name and value are concatenated with ``=`` as separator
187 #. The resulting strings are concatenated with ``&`` as separator
189 #. URL parameter string is used together with the secret key
190 to create a `HMAC-SHA1`__ digest
192 #. Digest is appended to the URL as ``asignature``
194 __ http://tools.ietf.org/html/rfc5849#section-3.4.1.3.2
195 __ http://tools.ietf.org/html/rfc5849#section-3.6
196 __ http://tools.ietf.org/html/rfc5849#section-3.4.2
204 The ``docs/`` directory contains an example PHP client implementation.
206 We want to create a screenshot of ``http://example.org/`` in size 400x300,
207 using the browser size of 1024x768::
209 http://example.org/phancap/get.php?swidth=400&sheight=300&url=http%3A%2F%2Fexample.org%2F&bwidth=1024&bheight=768
211 Phancap's config file contains::
217 Our parameters are thus:
224 ``url`` ``http://example.org/``
229 At first, we need to add parameters ``atimestamp`` and ``atoken``.
230 ``atimestamp`` is the current unix timestamp.
231 ``atoken`` is our user name: ``user``.
233 Now the parameter list is sorted:
238 ``atimestamp`` ``1396353987``
244 ``url`` ``http://example.org/``
247 The parameters are raw-url-encoded. The only value that changes is the url,
248 it becomes ``http%3A%2F%2Fexample.org%2F``.
250 Concatenating the name/value pairs leads to the following string::
252 atimestamp=1396353987&atoken=user&bheight=768&bwidth=1024&sheight=300&swidth=400&url=http%3A%2F%2Fexample.org%2F
254 Creating the HMAC digest with sha1, the calculated string and our key
255 ``secret`` gives us the following string::
257 9a12eac5ff859f9306eaaf5a18b9a931fe10b89d
259 This is the signature; it gets appended to the URL as ``asignature`` parameter.
267 - `cutycapt <http://cutycapt.sourceforge.net/>`_
268 - `imagemagick's <http://www.imagemagick.org/>`_ ``convert``
271 - Libraries (already included in the ``.phar``):
273 - PEAR's ``System.php``
279 ``phancap`` is licensed under the `AGPL v3`__ or later.
281 __ http://www.gnu.org/licenses/agpl.html
288 http://cweiske.de/phancap.htm
291 http://git.cweiske.de/phancap.git
293 Mirror: https://github.com/cweiske/phancap
299 Written by Christian Weiske, cweiske@cweiske.de
305 All of those are open source:
307 * http://code.google.com/p/browsershots/ (python)
308 * https://github.com/gre/screenshot-webservice (scala)