standaniels / image-generator
A package to generate random images.
Installs: 80 362
Dependents: 0
Suggesters: 0
Security: 0
Stars: 13
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.3|^8.0
- ext-exif: *
- ext-gd: *
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-08-27 13:35:10 UTC
README
This package makes generating images easy. Use them for placeholders without being dependent on some external service.
use StanDaniels\ImageGenerator\Canvas; use StanDaniels\ImageGenerator\Color; use StanDaniels\ImageGenerator\Image; use StanDaniels\ImageGenerator\Shape\Shape; $transparency = random_int(60, 80) / 100; $canvas = Canvas::create(400, 400, 2) ->background(Color::random($transparency)); for ($i = random_int(100, 150); $i > 0; $i--) { $transparency = random_int(60, 80) / 100; Shape::random($canvas, Color::random($transparency))->draw(); } // By default, the image is stored in the directory used for temporary files $image = Image::create($canvas);
Of which this could be the output:
Using color palettes
If you would like to generate an image based on a given set of colors like the one below, you can do it like this.
use StanDaniels\ImageGenerator\Canvas; use StanDaniels\ImageGenerator\Color; use StanDaniels\ImageGenerator\Image; use StanDaniels\ImageGenerator\Shape\Shape; $colors = [ new Color(73, 78, 109), new Color(214, 119, 98), new Color(144, 180, 148), new Color(237, 203, 150), new Color(136, 80, 83), ]; $canvas = Canvas::create(400, 400, 2) ->background(new Color(34, 36, 50)); for ($i = random_int(50, 100); $i > 0; $i--) { $color = clone $colors[random_int(0, count($colors) - 1)]; $color->setAlpha(random_int(50, 60) / 100); Shape::random($canvas, $color)->draw(); } $image = Image::create($canvas);
The output would be something like this:
Installation
You can install the package via composer:
composer require standaniels/image-generator
License
The MIT License (MIT). Please see License File for more information.