PHP Classes

PHP Blockies: Generate blocky images from a given seed string

Recommend this page to a friend!
  Info   View files Documentation   View files View files (22)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 58 This week: 1All time: 10,492 This week: 560Up
Version License PHP version Categories
blockies 1.0Custom (specified...5Algorithms, PHP 5, Graphics
Description 

Author

This package can generate blocky images from a given seed string.

It can generate an image with blocks of colored rectangles, having each rectangle color being defined from the values of a given seed string.

The package can save the resulting image in SVG format to a string of image data. The size and the background color of the final blocky image are configurable parameters.

Innovation Award
PHP Programming Innovation award nominee
June 2021
Number 6
Blockies are images that can represent a given text graphically.

This package can generate blocky images for a given text in SVG formats to be displayed in multiple sizes with good quality.

Manuel Lemos
Picture of Isa Eken
  Performance   Level  
Name: Isa Eken <contact>
Classes: 20 packages by
Country: Turkey Turkey
Age: 21
All time rank: 276644 in Turkey Turkey
Week rank: 52 Up2 in Turkey Turkey Up
Innovation award
Innovation award
Nominee: 13x

Documentation

PHP Blockies

The php alternative for download13/blockies js package.

isaeken/blockies isaeken/blockies isaeken/blockies isaeken/blockies isaeken/blockies isaeken/blockies isaeken/blockies isaeken/blockies isaeken/blockies isaeken/blockies isaeken/blockies isaeken/blockies

$blockies = new \IsaEken\Blockies\Blockies;
$blockies->draw();

echo $blockies->svg(); // <svg...
$blockies->image()->save('image.jpg'); // save generated image
echo $blockies->image()->encode('data-url')->encoded; // data:image/png;base64...

Installation

You can install with using composer.

composer require isaeken/blockies

Usage

Create the instance first.

$blockies = new \IsaEken\Blockies\Blockies([
    'seed' => '130ef2f0a8b713',
    'size' => 64,
    'background' => \Spatie\Color\Hex::fromString('#ff0000')->toHsl(),
]);

// or

$blockies = new \IsaEken\Blockies\Blockies;

draw them.

$blockies->draw();

You can use this as SVG.

file_put_contents('image.svg', $blockies->svg());

or use this with Intervention\Image

$blockies->image()->greyscale()->save('black_and_white.jpg');

recreate your seed

$blockies->refresh();
$blockies->image(); // this is a new image.

resize and change background

$blockies
    ->setSize(120)
    ->setBackground(\Spatie\Color\Hex::fromString('#00ff00')->toHsl())
    ->draw()
    ->image();

change seed

$blockies->setSeed('130ef2f0a8b713')->draw()->image();

get values

$blockies->getSeed(); // string
$blockies->getBackground(); // \Spatie\Color\Hsl
$blockies->getSize(); // int

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.


  Files folder image Files  
File Role Description
Files folder imageimages (12 files)
Files folder imagesrc (4 files)
Files folder imagetests (2 files)
Plain text file composer.json Data Auxiliary data
Plain text file LICENSE.md Lic. License text
Plain text file phpunit.xml.dist Data Auxiliary data
Plain text file README.md Doc. Documentation

  Files folder image Files  /  images  
File Role Description
  Image file 1.jpeg Icon Icon image
  Image file 10.jpeg Icon Icon image
  Image file 11.jpeg Icon Icon image
  Image file 12.jpeg Icon Icon image
  Image file 2.jpeg Icon Icon image
  Image file 3.jpeg Icon Icon image
  Image file 4.jpeg Icon Icon image
  Image file 5.jpeg Icon Icon image
  Image file 6.jpeg Icon Icon image
  Image file 7.jpeg Icon Icon image
  Image file 8.jpeg Icon Icon image
  Image file 9.jpeg Icon Icon image

  Files folder image Files  /  src  
File Role Description
  Plain text file Blockies.php Class Class source
  Plain text file Helpers.php Class Class source
  Plain text file Options.php Class Class source
  Plain text file Rectangle.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file images.json Data Auxiliary data
  Plain text file RenderTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:58
This week:1
All time:10,492
This week:560Up