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.

In Java 3 = 12

And then, after all that bashing of PHP being ugly and unpredictable, here comes this:

System.out.println(1 + 2 + " = " + 1 + 2);
// Output:
3 = 12

I understand why this happens, and how to work around it.  But I wasn’t expecting something as … simple … from the oh magestic Java.

Public JSON APIs

Public APIs is a collective list of free JSON APIs for use in web development.  You can find there web services for all kind of data – anything from weather and currency exchange, through government database, to random snippets like GIF images, Lorem Ipsum text, and quotes.