Documentation for crwlr / crawler-ext-browser (v1.3)

Attention: You're currently viewing the documentation for v1.3 of the crawler-ext-browser package.
This is not the latest version of the package.
If you didn't navigate to this version intentionally, you can click here to switch to the latest version.

Get the most used Colors from an Image

This step gets you the most used colors from an image. It's mainly meant to be used with screenshots, but can of course be used with any image. The step's input must be the path to an image on the filesystem.

This step finds the most used colors from an image. While primarily intended for use with screenshots, it can be applied to any image. The step requires the input to be the path to an image file on the filesystem (or a RespondedRequestWithScreenshot output object from a screenshot step).

use Crwlr\Crawler\HttpCrawler;
use Crwlr\CrawlerExtBrowser\Steps\GetColors;
use Crwlr\CrawlerExtBrowser\Steps\Screenshot;

$crawler = HttpCrawler::make()->withUserAgent('MyCrawler');

$myStorePath = __DIR__ . '/storepath';

$crawler
    ->input('https://www.crwlr.software')
    ->addStep(
        Screenshot::loadAndTake($myStorePath)
            ->addToResult(['url', 'screenshotPath'])
    )
    ->addStep(
        GetColors::fromImage()
            ->onlyAbovePercentageOfImage(0.5)
            ->addToResult()
    );

$crawler->runAndDump();

This produces output like:

array(3) {
  ["url"]=>
  string(26) "https://www.crwlr.software"
  ["screenshotPath"]=>
  string(134) "/Users/john/storepath/f9075416625304d94720e90165c9cc04-1709588778.png"
  ["colors"]=>
  array(7) {
    [0]=>
    array(5) {
      ["red"]=>
      int(249)
      ["green"]=>
      int(250)
      ["blue"]=>
      int(252)
      ["rgb"]=>
      string(13) "(249,250,252)"
      ["percentage"]=>
      float(55.7)
    }
    [1]=>
    array(5) {
      ["red"]=>
      int(255)
      ["green"]=>
      int(255)
      ["blue"]=>
      int(255)
      ["rgb"]=>
      string(13) "(255,255,255)"
      ["percentage"]=>
      float(25.7)
    }
    [2]=>
    array(5) {
      ["red"]=>
      int(14)
      ["green"]=>
      int(42)
      ["blue"]=>
      int(54)
      ["rgb"]=>
      string(10) "(14,42,54)"
      ["percentage"]=>
      float(5.1)
    }
    [3]=>
    array(5) {
      ["red"]=>
      int(54)
      ["green"]=>
      int(65)
      ["blue"]=>
      int(84)
      ["rgb"]=>
      string(10) "(54,65,84)"
      ["percentage"]=>
      float(3.5)
    }
    [4]=>
    array(5) {
      ["red"]=>
      int(74)
      ["green"]=>
      int(160)
      ["blue"]=>
      int(112)
      ["rgb"]=>
      string(12) "(74,160,112)"
      ["percentage"]=>
      float(3.3)
    }
    [5]=>
    array(5) {
      ["red"]=>
      int(68)
      ["green"]=>
      int(64)
      ["blue"]=>
      int(61)
      ["rgb"]=>
      string(10) "(68,64,61)"
      ["percentage"]=>
      float(1.5)
    }
    [6]=>
    array(5) {
      ["red"]=>
      int(230)
      ["green"]=>
      int(231)
      ["blue"]=>
      int(235)
      ["rgb"]=>
      string(13) "(230,231,235)"
      ["percentage"]=>
      float(1)
    }
  }
}