PHPackages                             fahimhossain/laravel-ai-tryon - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. fahimhossain/laravel-ai-tryon

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

fahimhossain/laravel-ai-tryon
=============================

A reusable Laravel package that adds AI-powered ecommerce virtual try-on previews.

v1.0.0(3w ago)01MITPHPPHP ^8.1CI passing

Since May 16Pushed 3w agoCompare

[ Source](https://github.com/alifhossain174/Laravel-AI-Try-On-Package)[ Packagist](https://packagist.org/packages/fahimhossain/laravel-ai-tryon)[ RSS](/packages/fahimhossain-laravel-ai-tryon/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (14)Versions (2)Used By (0)

Laravel AI Try-On
=================

[](#laravel-ai-try-on)

A reusable Laravel Composer package that adds an ecommerce "Try Out" button and modal to product detail pages. Shoppers upload their own photo, the package sends that photo plus the product image to an AI image-editing provider, and the generated virtual try-on preview is displayed in the modal.

The default provider is Google Gemini image generation through the Gemini API. Model names are configuration values, so you can use Nano Banana / Gemini Flash Image variants, newer Gemini image models, OpenAI, Replicate, or your own provider implementation without changing application code.

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

[](#installation)

```
composer require fahimhossain/laravel-ai-tryon
```

Publish the package files:

```
php artisan vendor:publish --tag=ai-tryon-config
php artisan vendor:publish --tag=ai-tryon-assets
php artisan vendor:publish --tag=ai-tryon-migrations
```

Or publish everything at once:

```
php artisan ai-tryon:install
php artisan migrate
```

Environment
-----------

[](#environment)

```
AI_TRYON_PROVIDER=gemini
GEMINI_API_KEY=
GEMINI_IMAGE_MODEL=gemini-2.5-flash-image
GEMINI_BASE_URL=https://generativelanguage.googleapis.com/v1beta
AI_TRYON_DISK=public
QUEUE_CONNECTION=database
AI_TRYON_PREMIUM_URL=https://example.com/upgrade
```

Google currently documents Gemini image generation through `generateContent` with text and inline image parts. Nano Banana model names can change, so keep `GEMINI_IMAGE_MODEL` in your environment or config rather than hardcoding a provider class.

Blade Usage
-----------

[](#blade-usage)

Place the component below your product image:

```

```

Supported product types are configurable and include `shirt`, `t-shirt`, `pant`, `cap`, `dress`, `shoes`, `accessory`, and `other`.

The component renders a button, upload modal, selected-photo preview, loading state, generated image, and clear error messages. It uses plain JavaScript and CSS published to `public/vendor/ai-tryon`.

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

[](#configuration)

Publish `config/ai-tryon.php` and update:

```
'provider' => env('AI_TRYON_PROVIDER', 'gemini'),

'providers' => [
    'gemini' => [
        'api_key' => env('GEMINI_API_KEY'),
        'model' => env('GEMINI_IMAGE_MODEL', 'gemini-2.5-flash-image'),
        'base_url' => env('GEMINI_BASE_URL', 'https://generativelanguage.googleapis.com/v1beta'),
    ],
],
```

To add a custom provider, bind your implementation to:

```
FahimHossain\LaravelAiTryon\Contracts\AiTryOnProviderInterface::class
```

The provider must return a `FahimHossain\LaravelAiTryon\Data\TryOnResult`.

Usage Limits and Premium CTA
----------------------------

[](#usage-limits-and-premium-cta)

The package tracks usage in `ai_tryon_usages`, not the external provider quota. This is intentional because AI providers do not reliably expose package-level free quota state to your Laravel app.

Limits are checked by authenticated `user_id`, with guest fallback to IP address:

```
'limits' => [
    'free_generations_per_user' => 5,
    'free_generations_per_ip' => 3,
    'daily_generations_per_user' => 20,
],
```

When a limit is exceeded, the endpoint returns JSON with `code: limit_exceeded` and the configured `premium_url` so the frontend can show an upgrade CTA.

Queue Setup
-----------

[](#queue-setup)

Queueing is enabled by default:

```
'queue' => [
    'enabled' => true,
    'connection' => env('AI_TRYON_QUEUE_CONNECTION', env('QUEUE_CONNECTION', 'database')),
],
```

For the database queue:

```
php artisan queue:table
php artisan migrate
php artisan queue:work
```

Set `ai-tryon.queue.enabled` to `false` for synchronous local testing.

Privacy Notes
-------------

[](#privacy-notes)

The package validates MIME type and max file size, never exposes API keys to the frontend, and uses Laravel CSRF protection on the upload endpoint.

User photos are stored temporarily so queued jobs can process them. By default, uploads are deleted after generation and the stored user-photo path is cleared:

```
'privacy' => [
    'store_user_uploads' => false,
    'auto_delete_uploads' => true,
    'require_consent' => false,
],
```

Show shoppers a clear consent and accuracy notice. AI try-on previews may be inaccurate and should not be treated as a guaranteed product fit.

Provider Details
----------------

[](#provider-details)

Gemini requests send:

- the configured prompt
- the uploaded shopper photo as inline base64 image data
- the product image as inline base64 image data
- `generationConfig.responseModalities` including image output

Generated images are saved to the configured Laravel storage disk.

OpenAI and Replicate provider classes are included as configurable starting points. Production Replicate models vary by schema, so adjust `providers.replicate.input_keys` or pass custom input options from your application if needed.

Routes
------

[](#routes)

The package registers:

- `POST /ai-tryon/generate`
- `GET /ai-tryon/generations/{uuid}`

You can change prefix and middleware in config.

Local Development and Testing
-----------------------------

[](#local-development-and-testing)

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

The tests use Orchestra Testbench and SQLite in memory.

Packagist Publishing
--------------------

[](#packagist-publishing)

1. Use your real package name in `composer.json`, for example `fahimhossain/laravel-ai-tryon`.
2. Keep the namespace consistent with your autoload mapping, for example `FahimHossain\\LaravelAiTryon`.
3. Push the repository to GitHub.
4. Create a Packagist package pointing to the GitHub repository.
5. Tag releases with SemVer, for example `v1.0.0`.

License
-------

[](#license)

MIT.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance95

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

24d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/62ab568d9207a71c9136dd0c4069eb61479f9fd7af4927c66a9366c9ee9f42f4?d=identicon)[alifhossain174](/maintainers/alifhossain174)

---

Top Contributors

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

---

Tags

laravelaiecommerceGemininano bananaVirtual Try-On

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fahimhossain-laravel-ai-tryon/health.svg)

```
[![Health](https://phpackages.com/badges/fahimhossain-laravel-ai-tryon/health.svg)](https://phpackages.com/packages/fahimhossain-laravel-ai-tryon)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9732.3M121](/packages/roots-acorn)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k14.1M120](/packages/laravel-pulse)[flarum/core

Delightfully simple forum software.

261.4M2.2k](/packages/flarum-core)[laravel/ai

The official AI SDK for Laravel.

9782.1M153](/packages/laravel-ai)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

76318.2M110](/packages/laravel-mcp)

PHPackages © 2026

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