PHPackages                             laratusk/pictomock - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. laratusk/pictomock

ActiveLibrary[Testing &amp; Quality](/categories/testing)

laratusk/pictomock
==================

Lightweight fake/placeholder image generator for PHP testing and mock data. Supports SVG, PNG, JPEG, GIF, WebP. Framework-agnostic with Laravel integration.

v1.0.0(2mo ago)10MITPHPPHP ^8.1

Since Feb 27Pushed 2mo agoCompare

[ Source](https://github.com/laratusk/pictomock)[ Packagist](https://packagist.org/packages/laratusk/pictomock)[ RSS](/packages/laratusk-pictomock/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

PictoMock
=========

[](#pictomock)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5421159c07888a0d9a87a9ec6765033135feb48759113b8be26c8586ba1a56ed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6172617475736b2f706963746f6d6f636b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laratusk/pictomock)[![PHP Version](https://camo.githubusercontent.com/68693cf5f6c0e19c9da574d5c57ccebbe00ed82c4ceddfcd98c407ad0f9fe542/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6c6172617475736b2f706963746f6d6f636b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laratusk/pictomock)[![Tests](https://camo.githubusercontent.com/493b9e47a549386e3773582ee372d2175cacc3963337da72dfcb9558bafc7ecd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c6172617475736b2f706963746f6d6f636b2f74657374732e796d6c3f7374796c653d666c61742d737175617265266c6162656c3d7465737473)](https://github.com/laratusk/pictomock/actions)[![License: MIT](https://camo.githubusercontent.com/458425f8985b0b0c8a736cffe75e05a098e3d77906acddbcad2bfc54492a4e02/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

**PictoMock** is a lightweight, framework-agnostic PHP library for generating fake placeholder images — perfect for testing, seeding databases, and prototyping. It supports SVG (zero dependencies), PNG, JPEG, GIF, WebP, and WBMP via the GD extension, with a clean fluent API and first-class Laravel and FakerPHP integration.

---

Features
--------

[](#features)

- Generate placeholder images in **SVG, PNG, JPEG, GIF, WebP, WBMP**
- **SVG generation requires no GD extension** — works anywhere PHP runs
- **Fluent, immutable builder API** for readable configuration
- **Simple static API** for one-liners
- **Background color strategies**: random solid color, fixed hex color, two-color gradient
- **Optional text overlay** showing image dimensions (e.g. "400x300")
- **Laravel service provider, facade, and publishable config**
- **FakerPHP provider** for seamless integration with Faker-based factories
- PHP 8.1+, strict types, PSR-4, PSR-12

---

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

[](#installation)

```
composer require laratusk/pictomock
```

For raster image formats (PNG, JPEG, GIF, WebP, WBMP) the PHP **GD extension** is required:

```
# On Ubuntu/Debian:
sudo apt-get install php-gd

# On macOS with Homebrew:
brew install php && brew install gd
```

---

Quick Start
-----------

[](#quick-start)

```
use Laratusk\PictoMock\PictoMock;

// Fluent API
$path = PictoMock::make()
    ->width(400)
    ->height(300)
    ->format('png')
    ->save('/tmp/images');

// Static one-liner
$path = PictoMock::generate('/tmp/images', 400, 300, 'png');

// SVG — no GD needed
$path = PictoMock::make()->format('svg')->width(800)->height(600)->save('/tmp');

// With dimension text overlay
$path = PictoMock::make()->format('png')->width(300)->height(200)->withText()->save('/tmp');
```

---

Usage
-----

[](#usage)

### Static API

[](#static-api)

```
use Laratusk\PictoMock\PictoMock;

$path = PictoMock::generate(
    outputDir: '/tmp/images',
    width: 400,
    height: 300,
    format: 'jpeg',
);
```

Signature:

```
PictoMock::generate(
    string $outputDir,
    int $width = 300,
    int $height = 300,
    string|ImageFormat $format = 'png',
    ?BackgroundStrategyInterface $background = null,
    bool $showText = false,
    ?string $filename = null,
): string
```

### Fluent API

[](#fluent-api)

```
use Laratusk\PictoMock\PictoMock;

$path = PictoMock::make()
    ->width(1200)
    ->height(628)
    ->format('webp')
    ->withText()
    ->filename('og-image')     // custom filename (without extension)
    ->save('/var/www/public/images');
```

The builder is **immutable** — each method returns a new instance, making it safe to fork:

```
$base = PictoMock::make()->width(400)->height(300);
$png  = $base->format('png')->save('/tmp');
$svg  = $base->format('svg')->save('/tmp');
```

### Background Strategies

[](#background-strategies)

#### Random Color (default)

[](#random-color-default)

```
use Laratusk\PictoMock\BackgroundStrategies\RandomColor;

$path = PictoMock::make()
    ->background(new RandomColor())
    ->format('svg')
    ->save('/tmp');
```

#### Fixed Color

[](#fixed-color)

```
use Laratusk\PictoMock\BackgroundStrategies\FixedColor;

$path = PictoMock::make()
    ->background(new FixedColor('#4a90e2'))   // accepts #RRGGBB or #RGB
    ->format('png')
    ->save('/tmp');
```

#### Gradient Color

[](#gradient-color)

```
use Laratusk\PictoMock\BackgroundStrategies\GradientColor;

$path = PictoMock::make()
    ->background(new GradientColor('#ff6b6b', '#4ecdc4'))
    ->width(800)
    ->height(400)
    ->format('png')
    ->save('/tmp');
```

The gradient is rendered left-to-right for GD images and as an SVG `linearGradient` for SVG output.

### Text Overlay

[](#text-overlay)

Add the image dimensions as a centered text label:

```
$path = PictoMock::make()
    ->width(400)
    ->height(300)
    ->format('png')
    ->withText()          // renders "400x300" centered on the image
    ->save('/tmp');

// Or pass false to disable explicitly:
$path = PictoMock::make()->withText(false)->format('svg')->save('/tmp');
```

### SVG Generation (no GD required)

[](#svg-generation-no-gd-required)

```
$path = PictoMock::make()
    ->format('svg')
    ->width(1200)
    ->height(630)
    ->background(new GradientColor('#667eea', '#764ba2'))
    ->withText()
    ->save('/tmp/social-images');
```

The SVG generator uses PHP's built-in `DOMDocument` and requires only `ext-dom`.

---

Laravel Integration
-------------------

[](#laravel-integration)

### Auto-Discovery

[](#auto-discovery)

The service provider and facade are auto-discovered via `composer.json` `extra.laravel`. No manual registration needed for Laravel 5.5+.

### Publish Config

[](#publish-config)

```
php artisan vendor:publish --tag=pictomock-config
```

This publishes `config/pictomock.php` to your application.

### Facade

[](#facade)

```
use Laratusk\PictoMock\Laravel\PictoMockFacade as PictoMock;
// or with the alias:
use PictoMock;

$path = PictoMock::make()->format('svg')->width(400)->height(300)->save(storage_path('app/images'));
```

### Config Reference

[](#config-reference)

```
// config/pictomock.php
return [
    'width'            => 300,
    'height'           => 300,
    'format'           => 'png',
    'show_text'        => false,
    'output_dir'       => storage_path('app/pictomock'),
    'background'       => 'random',       // 'random' | 'fixed' | 'gradient'
    'background_color' => '#4a90e2',      // used when background = 'fixed'
    'gradient_colors'  => ['#4a90e2', '#7b2ff7'],  // used when background = 'gradient'
];
```

### Database Factories with FakerPHP

[](#database-factories-with-fakerphp)

Register the provider in your `AppServiceProvider` or a dedicated faker service provider:

```
// app/Providers/AppServiceProvider.php
use Laratusk\PictoMock\Faker\PictoMockFakerProvider;

public function register(): void
{
    $this->app->extend(\Faker\Generator::class, function ($faker) {
        $faker->addProvider(new PictoMockFakerProvider($faker, storage_path('app/pictomock')));
        return $faker;
    });
}
```

Then use it in factories:

```
// database/factories/PostFactory.php
public function definition(): array
{
    return [
        'title'         => $this->faker->sentence(),
        'thumbnail'     => $this->faker->pictoMock(800, 450, 'webp'),
        'thumbnail_url' => $this->faker->pictoMockUrl(800, 450, 'png'),
    ];
}
```

---

FakerPHP Integration (Standalone)
---------------------------------

[](#fakerphp-integration-standalone)

```
use Faker\Factory;
use Laratusk\PictoMock\Faker\PictoMockFakerProvider;

$faker = Factory::create();
$faker->addProvider(new PictoMockFakerProvider($faker, '/tmp/images'));

// Returns absolute path to the generated file
$path = $faker->pictoMock(400, 300, 'png');

// Returns data URI (data:image/png;base64,...)
$dataUri = $faker->pictoMockUrl(400, 300, 'svg');

// With dimension text overlay
$path = $faker->pictoMock(800, 600, 'jpeg', true);
```

### Available Faker Methods

[](#available-faker-methods)

MethodDescription`pictoMock(int $w, int $h, string $format, bool $text)`Generate image and return file path`pictoMockUrl(int $w, int $h, string $format)`Generate image and return data URI---

ImageFormat Enum
----------------

[](#imageformat-enum)

All supported formats are defined in `Laratusk\PictoMock\Enums\ImageFormat`:

CaseValueMIME TypeRequires GD`ImageFormat::SVG``svg``image/svg+xml`No`ImageFormat::PNG``png``image/png`Yes`ImageFormat::JPG``jpg``image/jpeg`Yes`ImageFormat::JPEG``jpeg``image/jpeg`Yes`ImageFormat::GIF``gif``image/gif`Yes`ImageFormat::WEBP``webp``image/webp`Yes`ImageFormat::WBMP``wbmp``image/vnd.wap.wbmp`Yes---

Testing
-------

[](#testing)

```
composer install
./vendor/bin/phpunit
```

Run only unit tests:

```
./vendor/bin/phpunit --testsuite Unit
```

Run only integration tests:

```
./vendor/bin/phpunit --testsuite Integration
```

---

Contributing
------------

[](#contributing)

Contributions are welcome! Please:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/my-feature`)
3. Write tests for your changes
4. Ensure all tests pass (`./vendor/bin/phpunit`)
5. Follow PSR-12 coding standards
6. Submit a pull request

Please open an issue before implementing large changes.

---

License
-------

[](#license)

The MIT License (MIT). See [LICENSE](LICENSE) for details.

###  Health Score

37

—

LowBetter than 82% of packages

Maintenance92

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

70d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/755245aa5e4ba6c690b039cedcce5a86cd01b4f00d490cd71f03e6377ac302d5?d=identicon)[laratusk](/maintainers/laratusk)

---

Top Contributors

[![azer1ghost](https://avatars.githubusercontent.com/u/27803185?v=4)](https://github.com/azer1ghost "azer1ghost (2 commits)")

---

Tags

phptestingimagefakermocksvgpngjpegfakeplaceholder

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/laratusk-pictomock/health.svg)

```
[![Health](https://phpackages.com/badges/laratusk-pictomock/health.svg)](https://phpackages.com/packages/laratusk-pictomock)
```

###  Alternatives

[blastcloud/guzzler

Supercharge your app or SDK with a testing library specifically for Guzzle.

272419.3k35](/packages/blastcloud-guzzler)[quizlet/hammock

Hammock is a stand-alone mocking library for Hacklang.

27445.5k](/packages/quizlet-hammock)[doppiogancio/mocked-client

A simple way to mock a client

2174.9k3](/packages/doppiogancio-mocked-client)[ybelenko/openapi-data-mocker

Library that generates fake data from Swagger 2.0|Openapi 3.0 spec

1230.5k1](/packages/ybelenko-openapi-data-mocker)

PHPackages © 2026

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