PHPackages                             microweber/screen - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. microweber/screen

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

microweber/screen
=================

A PHP Class to interact with PhantomJs and capture screenshot of a webpage

v1.0.6(9y ago)632226.0k↓18.9%190[29 issues](https://github.com/microweber/screen/issues)[1 PRs](https://github.com/microweber/screen/pulls)1MITPHPPHP &gt;=5.3

Since Jan 25Pushed 3y ago50 watchersCompare

[ Source](https://github.com/microweber/screen)[ Packagist](https://packagist.org/packages/microweber/screen)[ RSS](/packages/microweber-screen/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (1)Versions (9)Used By (1)

Screen
======

[](#screen)

Web site screenshot tool based on PHP and [PhantomJS](https://phantomjs.org/)You can use it to take screenshots for testing or monitoring service

Install
-------

[](#install)

Via Composer

```
$ composer require microweber/screen
```

If on any Unix system, you need to make the `bin` executable `chmod +x /path/to/screen/bin/phantomjs`

The directory `/path/to/screen/jobs` must be writable as well.

Linux requirements
------------------

[](#linux-requirements)

- FontConfig - `apt-get/yum install fontconfig`
- FreeType - `apt-get/yum install freetype*`

Usage
-----

[](#usage)

With this library you can make use of PhantomJs to screenshot a website.

Check our [demo](/demo) or read the following instructions.

Creating the object, you can either pass the URL on the constructor or set it later on

```
use Screen\Capture;

$url = 'https://github.com';

$screenCapture = new Capture($url);
// or
$screenCapture = new Capture();
$screenCapture->setUrl($url);
```

You can also set the browser dimensions

```
$screenCapture->setWidth(1200);
$screenCapture->setHeight(800);
```

you can set also DOM Element Position (top, left)

```
$screenCapture->setTop(100);
$screenCapture->setLeft(100);
```

This will output all the page including the content rendered beyond the setted dimensions (e.g.: all the scrollable content), if you want just the content inside those boudaries you need to clip the result

```
// You also need to set the width and height.
$screenCapture->setClipWidth(1200);
$screenCapture->setClipHeight(800);
```

Some webpages don't have a background color setted to the body, if you want you can set the color using this method

```
$screenCapture->setBackgroundColor('#ffffff');
```

You can also set the User Agent

```
$screenCapture->setUserAgentString('Some User Agent String');
```

And the resulted image type

```
// allowed types are 'jpg' and 'png', default is 'jpg'.
$screenCapture->setImageType(Screen\Image\Types\Png::FORMAT);
// or
$screenCapture->setImageType('png');
```

- If the format is `jpg` and the background color is not set, the default value will be `#FFFFFF`, if `png` the default background color will be transparent.

And most importantly, save the result

```
$fileLocation = '/some/dir/test.' . $screen->getImageType()->getFormat();
$screenCapture->save($fileLocation);

// you don't need to set the file extension
$fileLocation = '/some/dir/test';
$screenCapture->save($fileLocation); // Will automatically determine the extension type

echo $screenCapture->getImageLocation(); // --> /some/dir/test.png
```

Injection your own JS into the web page
---------------------------------------

[](#injection-your-own-js-into-the-web-page)

You can also run your own JS scripts or snippets before the screenshot.

For that we have the method `includeJs`, here are some usage examples:

```
// Including a remote file
$jQueryUrl = 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js';
$screenCapture->includeJs(new \Screen\Injection\Url($jQUeryUrl));

// Including a local file
$localFilePath = 'path/to/my/script.js';
$screenCapture->includeJs(new \Screen\Injection\LocalPath($localFilePath));

// Using the scripts included on the library
$screen->includeJs(new \Screen\Injection\Scripts\FacebookHideCookiesPolicy());
$screen->includeJs(new \Screen\Injection\Scripts\FacebookHideSignUp());

// Using a js snippet
$screen->includeJs("console.log('This is supa cool!');");
```

Just use this method before calling `save(...)`

Passing options to PhantomJS
----------------------------

[](#passing-options-to-phantomjs)

You can set the options that will be passed to the PhantomJS binary.

```
$screenCapture->setOptions([
    'ignore-ssl-errors' => 'yes',
    // '--ignore-ssl-errors' => 'yes', // dashes may be omitted
]);
```

Other configurations
--------------------

[](#other-configurations)

Additionally to the basic usage, you can set so extra configurations.

You can change the where the PhantomJS binary file is.

```
$screenCapture->binPath = '/path/to/bin/dir/';
// This will result in /path/to/bin/dir/phantomjs
```

Change the jobs location

```
$screenCapture->jobs->setLocation('/path/to/jobs/dir/');
echo $screenCapture->jobs->getLocation(); // -> /path/to/jobs/dir/
```

And set an output base location

```
$screenCapture->output->setLocation('/path/to/output/dir/');
echo $screenCapture->output->getLocation(); // -> /path/to/output/dir/

// if the output location is setted
$screenCapture->save('file.jpg');
// will save the file to /path/to/output/dir/file.jpg
```

You can also clean/delete all the generated job files like this:

```
$screenCapture->jobs->clean();
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Credits
-------

[](#credits)

- [Peter Ivanov](https://github.com/peter-mw)
- [André Filipe](https://github.com/MASNathan)
- [All Contributors](../../contributors)

Thanks to the [PhantomJS](https://phantomjs.org/ "Headless browser") ([LICENSE](https://github.com/ariya/phantomjs/blob/master/LICENSE.BSD)) guys for creating their awesome WebKit scripting interface.

This tool was originally created to take screenshots for [Microweber](https://microweber.com/ "Open Source CMS")

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity57

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~61 days

Total

8

Last Release

3336d ago

Major Versions

v1.0.6 → v2.0.0.x-dev2017-03-30

PHP version history (3 changes)v1.0.0PHP &gt;=5.3

v1.0.1PHP ~5.3

v2.0.0.x-devPHP &gt;=5.5.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/4dc06e05e127ad3192ef9797ace808069687140538add8e6dbad34ce50bcd1f8?d=identicon)[boksiora](/maintainers/boksiora)

---

Top Contributors

[![peter-mw](https://avatars.githubusercontent.com/u/5698247?v=4)](https://github.com/peter-mw "peter-mw (22 commits)")[![MASNathan](https://avatars.githubusercontent.com/u/2139464?v=4)](https://github.com/MASNathan "MASNathan (18 commits)")[![mbardelmeijer](https://avatars.githubusercontent.com/u/1583095?v=4)](https://github.com/mbardelmeijer "mbardelmeijer (3 commits)")[![pouu69](https://avatars.githubusercontent.com/u/8802261?v=4)](https://github.com/pouu69 "pouu69 (2 commits)")[![joshp23](https://avatars.githubusercontent.com/u/7341917?v=4)](https://github.com/joshp23 "joshp23 (1 commits)")[![KarloNjegovan](https://avatars.githubusercontent.com/u/23176610?v=4)](https://github.com/KarloNjegovan "KarloNjegovan (1 commits)")[![lahaxearnaud](https://avatars.githubusercontent.com/u/1364221?v=4)](https://github.com/lahaxearnaud "lahaxearnaud (1 commits)")[![noahcoffey](https://avatars.githubusercontent.com/u/382447?v=4)](https://github.com/noahcoffey "noahcoffey (1 commits)")[![sam0hack](https://avatars.githubusercontent.com/u/5379650?v=4)](https://github.com/sam0hack "sam0hack (1 commits)")[![sergey-nechaev](https://avatars.githubusercontent.com/u/3796512?v=4)](https://github.com/sergey-nechaev "sergey-nechaev (1 commits)")[![akiyamaSM](https://avatars.githubusercontent.com/u/12276076?v=4)](https://github.com/akiyamaSM "akiyamaSM (1 commits)")[![xuanskyer](https://avatars.githubusercontent.com/u/3071881?v=4)](https://github.com/xuanskyer "xuanskyer (1 commits)")[![al0mie](https://avatars.githubusercontent.com/u/5223895?v=4)](https://github.com/al0mie "al0mie (1 commits)")[![alnviana](https://avatars.githubusercontent.com/u/31132223?v=4)](https://github.com/alnviana "alnviana (1 commits)")[![ashleyadams](https://avatars.githubusercontent.com/u/8956823?v=4)](https://github.com/ashleyadams "ashleyadams (1 commits)")

---

Tags

capturephantomjsscreenprint-screen

### Embed Badge

![Health badge](/badges/microweber-screen/health.svg)

```
[![Health](https://phpackages.com/badges/microweber-screen/health.svg)](https://phpackages.com/packages/microweber-screen)
```

###  Alternatives

[jakoch/phantomjs-installer

A Composer package which installs the PhantomJS binary (Linux, Windows, Mac) into `/bin` of your project.

1515.4M72](/packages/jakoch-phantomjs-installer)[hybridlogic/phantomjs

A PHP library to execute PhantomJS scripts and return their results.

57158.3k](/packages/hybridlogic-phantomjs)[urlbox/screenshots

Use urlbox to easily generate website thumbnail screenshots from a URL

14250.4k](/packages/urlbox-screenshots)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
