Transform your images as if they were made out of LEGO bricks.
Switch branches/tags
Nothing to show
Clone or download
ricardofiorani Merge pull request #2 from willemstuursma/closest-color
Improve mechanism that picks the closest color
Latest commit 7a91c1a Oct 11, 2018

PHP Legofy

Build Status Minimum PHP Version License Total Downloads Coding Standards Scrutinizer Code Quality Code Coverage

What is this ?

PHP Legofy is a PHP package that takes a static image and makes it so that it looks as if it was built out of LEGO.
It was inspired by the original Legofy made in Python

Basically it transforms this: Image of a beer Into this: Image of a legofied beer


  • PHP 7.1 (or above)
  • GD or ImageMagick

I tested it with GD only but I'm trusting intervention/image that this will work on ImageMagick as well.


Via composer:

$ composer require ricardofiorani/php-legofy

Via source:

$ git clone
$ cd php-legofy
$ composer install


require 'vendor/autoload.php';

// The multiplier for the amount of legos on your image, or "legolution" :)
$resolutionMultiplier = 1;

// When set to true it will only use lego colors that exists in real world.
$useLegoPalette = false;

$legofy = new \RicardoFiorani\Legofy\Legofy();

// $source can be any acceptable parameter for intervention/image
// Please see
$source = 'my/imagem/path/image.jpg';

 *@var Intervention\Image\Image 
$output = $legofy->convertToLego($source, $resolutionMultiplier, $useLegoPalette);

// Please see and
echo $output->response();

For more examples of usage please see the usage examples on documentation