Browser screenshots with PHP and Google Chrome 59+

The release of Google Chrome 59 brought some really cool features.  One of them in particular was all over the technology news – headless mode.  Being able to run the browser engine without the graphical interface, and having control from the command line and API has many benefits.

One of the benefits is being able to take web page screenshots.  “Easily convert webpages to images using PHP” is one of the many blogs and articles that explain how to do it, using your preferred programming language (or mine in this case).  Browsershot is a very simple PHP library, which you can install with Composer and start using straight away.

I’ve tried it out and it works pretty well.  The screenshot above has been taken by the following script:

<?php 
require_once 'vendor/autoload.php';
use Spatie\Browsershot\Browsershot;

Browsershot::url('https://mamchenkov.net')
  ->windowSize(1600,900)
  ->save('screenshot.png');

Improving the output of PHPUnit

Via “Improving the output of PHPUnit” I’ve learned about PHPUnit Emoji Result Printer.  Obviously, this sounds like fun, but I’m also sure there is some really smart way of using this.

Too bad I couldn’t try it on one of our work projects just yet, as this requires PHPUnit 6+, while we are still on PHPUnit 5.7.  But we’ll get there.