PHPackages                             standaniels/image-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. standaniels/image-generator

ActiveLibrary[Image &amp; Media](/categories/media)

standaniels/image-generator
===========================

A package to generate random images.

1.1.0(5y ago)1699.6k↓18.3%31MITCPHP ^7.3|^8.0CI failing

Since Aug 19Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/standaniels/image-generator)[ Packagist](https://packagist.org/packages/standaniels/image-generator)[ Docs](https://github.com/standaniels/image-generator)[ RSS](/packages/standaniels-image-generator/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (2)Versions (6)Used By (1)

Random Image Generator
======================

[](#random-image-generator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8ce8d42b3d59bc358e8f1bddcfe5c627d19d724bd7e55d397a1d1129f9412818/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7374616e64616e69656c732f696d6167652d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/standaniels/image-generator)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/d07888539fda42bebf76f56aa3f5324e414f25e857b4e4ebc8626183b2d3dfea/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f7374616e64616e69656c732f696d6167652d67656e657261746f722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/standaniels/image-generator)[![Total Downloads](https://camo.githubusercontent.com/2e9be54866f5c4571078f9d993881391ca8975e039335fc80bb4e33dc69d1c0f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7374616e64616e69656c732f696d6167652d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/standaniels/image-generator)

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:

[![A randomly generated image](https://user-images.githubusercontent.com/1199737/181206232-2606ba13-0236-4a1a-af6f-a0366a29e7c0.jpg)](https://user-images.githubusercontent.com/1199737/181206232-2606ba13-0236-4a1a-af6f-a0366a29e7c0.jpg)

Using color palettes
--------------------

[](#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.

[![Color palette](https://user-images.githubusercontent.com/1199737/181207233-b85a5e3a-0ea2-42a5-8263-2b4749eb5f0c.png)](https://user-images.githubusercontent.com/1199737/181207233-b85a5e3a-0ea2-42a5-8263-2b4749eb5f0c.png)

```
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:

[![A randomly generated image based on a given set of colors](https://user-images.githubusercontent.com/1199737/181207373-3179c998-d682-4094-abf6-1681455cafb0.jpg)](https://user-images.githubusercontent.com/1199737/181207373-3179c998-d682-4094-abf6-1681455cafb0.jpg)

Installation
------------

[](#installation)

The library is distributed as a C extension. You compile it once against your local PHP installation, then load it like any other `.so` extension.

### Requirements

[](#requirements)

RequirementNotesPHP ≥ 8.0Tested through PHP 8.5php-dev / php-develProvides `phpize` and the build headerslibgdPHP must be built with GD support (`ext-gd`)libexifPHP must be built with EXIF support (`ext-exif`)A C compilergcc or clangmakeStandard build toolOn Debian / Ubuntu:

```
sudo apt-get install php-dev php-gd php-exif build-essential
```

On Red Hat / Fedora / CentOS:

```
sudo dnf install php-devel php-gd php-exif gcc make
```

On macOS (with [Homebrew](https://brew.sh)):

```
brew install php
# php-config, phpize, and gd are included in the Homebrew php formula
```

### Build and install

[](#build-and-install)

The C source lives in the `ext/` directory.

```
cd ext/

# 1. Prepare the build environment
phpize

# 2. Configure (links against your active PHP installation automatically)
./configure

# 3. Compile
make

# 4. Install the .so into your PHP extension directory
sudo make install
```

`make install` copies `image_generator.so` to the directory shown by `php-config --extension-dir`.

### Enable the extension

[](#enable-the-extension)

Add the extension to your `php.ini`:

```
extension=image_generator
```

Find the right `php.ini` with:

```
php --ini
```

To enable it only for a single script without editing `php.ini`:

```
php -d extension=image_generator script.php
```

### Verify the installation

[](#verify-the-installation)

```
php -r "var_dump(extension_loaded('image_generator'));"
# → bool(true)
```

### Run the test suite

[](#run-the-test-suite)

The PHPT tests in `ext/tests/` are run with PHP's built-in test runner. From inside the `ext/` directory (after `make`):

```
make test
```

Or run them directly against the freshly built `.so`:

```
php run-tests.php -d extension=modules/image_generator.so tests/
```

License
-------

[](#license)

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

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance55

Moderate activity, may be stable

Popularity39

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 59.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~480 days

Total

3

Last Release

1913d ago

PHP version history (2 changes)1.0.0PHP ^7.1

1.1.0PHP ^7.3|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e323e86ae4be21fd808f892fe4292a5708a1fdb42bcdeceefa9e6a42b1bbf967?d=identicon)[standaniels](/maintainers/standaniels)

---

Top Contributors

[![standaniels](https://avatars.githubusercontent.com/u/1199737?v=4)](https://github.com/standaniels "standaniels (13 commits)")[![staninova](https://avatars.githubusercontent.com/u/60260890?v=4)](https://github.com/staninova "staninova (9 commits)")

---

Tags

imagephpplaceholder-imagerandomrandomimagegeneratorstandaniels

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/standaniels-image-generator/health.svg)

```
[![Health](https://phpackages.com/badges/standaniels-image-generator/health.svg)](https://phpackages.com/packages/standaniels-image-generator)
```

###  Alternatives

[intervention/image

PHP Image Processing

14.3k208.9M2.6k](/packages/intervention-image)[league/glide

Wonderfully easy on-demand image manipulation library with an HTTP based API.

2.6k53.3M146](/packages/league-glide)[liip/imagine-bundle

This bundle provides an image manipulation abstraction toolkit for Symfony-based projects.

1.7k40.0M246](/packages/liip-imagine-bundle)[spatie/image

Manipulate images with an expressive API

1.4k60.7M188](/packages/spatie-image)[multiavatar/multiavatar-php

Multicultural Avatar Generator

657171.0k6](/packages/multiavatar-multiavatar-php)[intervention/image-laravel

Laravel Integration of Intervention Image

1588.9M183](/packages/intervention-image-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
