PHPackages                             naim886/imgenerate-laravel-faker - 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. naim886/imgenerate-laravel-faker

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

naim886/imgenerate-laravel-faker
================================

A Laravel package to generate fake images using imgenerate.com API for testing and development with full customization support

1.2.0(7mo ago)2193MITPHPPHP ^7.4|^8.0|^8.1|^8.2|^8.3

Since Dec 2Pushed 7mo agoCompare

[ Source](https://github.com/naim886/imgenerate-laravel-faker)[ Packagist](https://packagist.org/packages/naim886/imgenerate-laravel-faker)[ RSS](/packages/naim886-imgenerate-laravel-faker/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (4)Versions (5)Used By (0)

Laravel Imgenerate Faker
========================

[](#laravel-imgenerate-faker)

[![Latest Version on Packagist](https://camo.githubusercontent.com/57f204170d171a73e35465a525b529bca581b843cd2ccf8aec630ea57fec4174/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e61696d3838362f696d67656e65726174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/naim886/imgenerate)[![Total Downloads](https://camo.githubusercontent.com/ed3d4ded53b0b4d323d4a92571f83af86d09618a22990a3992582256140b453d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e61696d3838362f696d67656e65726174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/naim886/imgenerate)

A Laravel package to generate fake images using [imgenerate.com](https://www.imgenerate.com) API for testing and development purposes. Perfect for seeding databases with realistic placeholder images.

Features
--------

[](#features)

- 🎨 Generate fake images with custom dimensions
- 🎯 Multiple image categories (nature, people, technology, etc.)
- 💾 Save images directly to Laravel storage
- 🔗 Get image URLs for external use
- 🎭 Integrate seamlessly with Laravel Faker
- 🚀 Easy to use and configure

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

[](#installation)

You can install the package via composer:

```
composer require naim886/imgenerate-laravel-faker
```

The package will automatically register itself.

Configuration
-------------

[](#configuration)

Optionally, you can publish the configuration file:

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

This will create a `config/imgenerate.php` file where you can customize default settings.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Imgenerate\LaravelFaker\Facades\Imgenerate;

// Generate a random image URL
$imageUrl = Imgenerate::url();

// Generate with specific dimensions
$imageUrl = Imgenerate::url(800, 600);

// Generate with custom text
$imageUrl = Imgenerate::url(800, 600, ['text' => 'My Custom Text']);

// Generate with all customization options
$imageUrl = Imgenerate::url(400, 400, [
    'bg' => '1e3a8a',           // Background color (hex without #)
    'text_color' => 'ffffff',    // Text color (hex without #)
    'font_size' => 24,           // Font size
    'angle' => 0,                // Text rotation angle (0-360)
    'text' => 'www.imgenerate.com', // Custom text
    'format' => 'jpg'            // Image format (jpg, png, webp)
]);
```

### Customization Parameters

[](#customization-parameters)

The package supports full customization of generated images:

- **width**: Image width in pixels (e.g., 400, 800, 1920)
- **height**: Image height in pixels (e.g., 400, 600, 1080)
- **bg**: Background color as hex code without # (e.g., '1e3a8a', 'ff5733')
- **text\_color**: Text color as hex code without # (e.g., 'ffffff', '000000')
- **font\_size**: Font size for text (e.g., 12, 24, 48)
- **angle**: Text rotation angle in degrees 0-360 (e.g., 0, 45, 90)
- **text**: Custom text to display on image (e.g., 'Hello World', 'Product Name')
- **format**: Image format (e.g., 'jpg', 'png', 'webp')

### Using Fluent Interface

[](#using-fluent-interface)

```
// Chain methods for clean configuration
$imageUrl = Imgenerate::dimensions(400, 400)
    ->bg('1e3a8a')
    ->textColor('ffffff')
    ->fontSize(24)
    ->angle(0)
    ->text('www.imgenerate.com')
    ->format('jpg')
    ->get();
```

### Using with Laravel Faker

[](#using-with-laravel-faker)

In your model factories:

```
use Illuminate\Database\Eloquent\Factories\Factory;
use Imgenerate\LaravelFaker\Facades\Imgenerate;

class ProductFactory extends Factory
{
    public function definition()
    {
        return [
            'name' => $this->faker->name,
            'description' => $this->faker->paragraph,
            'image' => Imgenerate::url(800, 600, [
                'text' => 'Product',
                'bg' => 'e5e7eb',
                'text_color' => '1f2937'
            ]),
            // or save to storage
            'image_path' => Imgenerate::save(800, 600, [
                'text' => 'Product Image',
                'bg' => 'f3f4f6',
                'text_color' => '111827'
            ], 'products'),
        ];
    }
}
```

### Using the Faker Provider

[](#using-the-faker-provider)

Add the provider to your factory or test:

```
$faker = \Faker\Factory::create();
$faker->addProvider(new \Imgenerate\LaravelFaker\FakerProvider($faker));

// Now you can use
$imageUrl = $faker->imgenerateUrl(800, 600);
$imageUrl = $faker->imgenerateUrl(800, 600, [
    'text' => 'Nature',
    'bg' => '10b981',
    'text_color' => 'ffffff'
]);
$savedPath = $faker->imgenerateSave(800, 600, [
    'text' => 'Saved Image',
    'bg' => '3b82f6'
], 'images');
```

### Save Images to Storage

[](#save-images-to-storage)

```
// Save to default disk (usually 'public')
$path = Imgenerate::save(800, 600);

// Save with custom options
$path = Imgenerate::save(800, 600, [
    'text' => 'Saved Image',
    'bg' => '1e3a8a',
    'text_color' => 'ffffff',
    'font_size' => 24
]);

// Save to specific disk
$path = Imgenerate::disk('s3')->save(800, 600, [
    'text' => 'Cloud Storage'
]);

// Save to specific folder
$path = Imgenerate::save(800, 600, [
    'text' => 'Nature',
    'bg' => '10b981'
], 'uploads/images');
```

### Advanced Usage

[](#advanced-usage)

```
// Chain methods for configuration
$imageUrl = Imgenerate::text('Beautiful Landscape')
    ->dimensions(1920, 1080)
    ->bg('059669')
    ->textColor('ffffff')
    ->fontSize(48)
    ->get();

// Generate multiple images
$images = Imgenerate::multiple(5, 800, 600, [
    'text' => 'Gallery Image',
    'bg' => 'd97706',
    'text_color' => 'ffffff'
]);

// Download image content
$content = Imgenerate::download(800, 600, [
    'text' => 'Downloaded Image',
    'bg' => '7c3aed'
]);

// Complex example with all options
$imageUrl = Imgenerate::url(1200, 630, [
    'bg' => '1e40af',
    'text_color' => 'fbbf24',
    'font_size' => 32,
    'angle' => 0,
    'text' => 'Welcome to Our Site',
    'format' => 'png'
]);
```

### Practical Examples

[](#practical-examples)

```
// Generate a logo placeholder
$logo = Imgenerate::url(200, 200, [
    'bg' => '000000',
    'text_color' => 'ffffff',
    'font_size' => 48,
    'text' => 'LOGO'
]);

// Generate a banner
$banner = Imgenerate::url(1200, 400, [
    'bg' => '3b82f6',
    'text_color' => 'ffffff',
    'font_size' => 56,
    'text' => 'SALE - 50% OFF'
]);

// Generate a social media image
$socialImage = Imgenerate::url(1200, 630, [
    'bg' => 'ec4899',
    'text_color' => 'ffffff',
    'font_size' => 42,
    'text' => 'Check out our new blog post!'
]);

// Generate a product thumbnail
$thumbnail = Imgenerate::url(300, 300, [
    'bg' => 'f3f4f6',
    'text_color' => '1f2937',
    'font_size' => 18,
    'text' => 'Product'
]);
```

Configuration Options
---------------------

[](#configuration-options)

```
return [
    // Default image width
    'default_width' => 640,

    // Default image height
    'default_height' => 480,

    // Default category (deprecated - use 'default_text' instead)
    'default_category' => null,

    // Default storage disk
    'default_disk' => 'public',

    // Default storage path
    'default_path' => 'images',

    // Cache images (coming soon)
    'cache_enabled' => false,

    // API timeout in seconds
    'timeout' => 30,

    // Default background color (hex without #)
    'default_bg' => null,

    // Default text color (hex without #)
    'default_text_color' => null,

    // Default font size
    'default_font_size' => null,

    // Default text angle (0-360)
    'default_angle' => 0,

    // Default text to display
    'default_text' => null,

    // Default image format (jpg, png, webp)
    'default_format' => null,
];
```

You can also set these via environment variables in your `.env` file:

```
IMGENERATE_DEFAULT_WIDTH=800
IMGENERATE_DEFAULT_HEIGHT=600
IMGENERATE_DEFAULT_BG=1e3a8a
IMGENERATE_DEFAULT_TEXT_COLOR=ffffff
IMGENERATE_DEFAULT_FONT_SIZE=24
IMGENERATE_DEFAULT_ANGLE=0
IMGENERATE_DEFAULT_TEXT="Placeholder"
IMGENERATE_DEFAULT_FORMAT=jpg
IMGENERATE_DEFAULT_DISK=public
IMGENERATE_DEFAULT_PATH=images
IMGENERATE_TIMEOUT=30
```

Example: Complete Model Factory
-------------------------------

[](#example-complete-model-factory)

```
