{"id":37012960,"url":"https://github.com/kdosiodjinud/ai-generate-image-by-reference","last_synced_at":"2026-01-14T01:15:28.419Z","repository":{"id":298446538,"uuid":"999970221","full_name":"kdosiodjinud/ai-generate-image-by-reference","owner":"kdosiodjinud","description":"A PHP library to generate images in the style of a reference image using the OpenAI Image API.","archived":false,"fork":false,"pushed_at":"2025-06-20T21:16:22.000Z","size":16,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-26T20:51:01.288Z","etag":null,"topics":["ai","generator","image-processing","images","openai","reference"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kdosiodjinud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-11T04:35:32.000Z","updated_at":"2025-10-03T04:07:12.000Z","dependencies_parsed_at":"2025-06-11T06:46:37.608Z","dependency_job_id":null,"html_url":"https://github.com/kdosiodjinud/ai-generate-image-by-reference","commit_stats":null,"previous_names":["kdosiodjinud/ai-generate-image-by-reference"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/kdosiodjinud/ai-generate-image-by-reference","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdosiodjinud%2Fai-generate-image-by-reference","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdosiodjinud%2Fai-generate-image-by-reference/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdosiodjinud%2Fai-generate-image-by-reference/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdosiodjinud%2Fai-generate-image-by-reference/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kdosiodjinud","download_url":"https://codeload.github.com/kdosiodjinud/ai-generate-image-by-reference/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdosiodjinud%2Fai-generate-image-by-reference/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28407663,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","generator","image-processing","images","openai","reference"],"created_at":"2026-01-14T01:15:27.852Z","updated_at":"2026-01-14T01:15:28.407Z","avatar_url":"https://github.com/kdosiodjinud.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🧠🎨 AiGenerateImageByReference\n\nA PHP library to generate images in the style of a reference image using the OpenAI Image API.\n\n---\n\n## ⚙️ Installation\n\n```bash\ncomposer require kdosiodjinud/ai-generate-image-by-reference\n```\n\n\u003e Requires PHP 8.1+, `guzzlehttp/guzzle`, and `psr/log`.\n\n---\n\n## 🚀 Usage\n\n```php\nuse AiGenerateImageByReference\\AiGenerateImageByReference;\nuse Monolog\\Logger;\nuse Monolog\\Handler\\StreamHandler;\n\n$apiKey = 'sk-...';\n\n$logger = new Logger('ai');\n$logger-\u003epushHandler(new StreamHandler('php://stdout'));\n\n$ai = new AiGenerateImageByReference($apiKey, $logger);\n\n$generatedImageBase64 = $ai\n    -\u003esetStyleImage('/path/to/reference-style.png') // reference image for style\n    -\u003eaddContentImage('/path/to/content-image.png', 'Add glasses to the person') // content with description\n    -\u003egenerate('A sunny outdoor scene with the person reading a book.');\n\nif ($generatedImageBase64) {\n    file_put_contents('output.png', base64_decode($generatedImageBase64));\n}\n```\n\n---\n\n## 🔧 Advanced Usage (Custom HTTP Client)\n\nYou can pass a custom Guzzle client (e.g. with a mock handler for testing):\n\n```php\nuse GuzzleHttp\\Client;\n\n$customClient = new Client([...]);\n$ai = new AiGenerateImageByReference($apiKey, $logger, $customClient);\n```\n\n---\n\n## 🧰 Options (`$options`)\n\nPass an options array to `generate()`:\n\n| Key          | Description                                  | Default Value |\n| ------------ | -------------------------------------------- | ------------- |\n| `MODEL`      | OpenAI model                                 | `gpt-image-1` |\n| `SIZE`       | Image size (`1024x1024`, etc.)               | `1024x1024`   |\n| `N`          | Number of images                             | `1`           |\n| `BACKGROUND` | Background (`transparent`, `opaque`, `auto`) | `transparent` |\n\nUnknown keys will be ignored with a warning if logger is set.\n\n---\n\n## 🧪 Running Tests\n\n```bash\ncomposer install\nvendor/bin/phpunit\n```\n\n\u003e All tests live in `tests/` and are PSR-4 autoloaded.\\\n\u003e Uses Guzzle's `MockHandler` for full offline test coverage.\n\n---\n\n## 🧼 Code Style\n\nThis project uses **PHP-CS-Fixer** with strict PSR-12 rules.\n\n### ▶️ Run it\n\n```bash\nvendor/bin/php-cs-fixer fix\n```\n\n\u003e 💡 If you're on PHP 8.4 (or fighting entropy), run it with:\n\u003e\n\u003e ```bash\n\u003e PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix\n\u003e ```\n\n---\n\n## 🧠 How It Works\n\n- First image set via `setStyleImage()` defines the visual style.\n- Additional images via `addContentImage()` define the content (e.g. characters).\n- Prompt describes final composition.\n- Uses `multipart/form-data` to call OpenAI API.\n- Returns base64-encoded image.\n\n---\n\n## 📦 Requirements\n\n- PHP 8.1+\n- OpenAI API key with image generation access\n- `guzzlehttp/guzzle`\n- (optional) `psr/log` for logging\n\n---\n\n## 📬 Want to contribute?\n\nSure, fork it. Or open a PR.\\\nOr just write a poem about AI and post it on your fridge. We approve.\n\n---\n\n## ☕ License\n\nMIT. Hack it, fork it, print it on a mug.\n\n---\n\n## 🧪 Real-World Example\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\OpenAi\\Tool;\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\nuse AiGenerateImageByReference\\AiGenerateImageByReference;\nuse Monolog\\Handler\\StreamHandler;\nuse Monolog\\Logger;\n\n$apiKey = 'sk-your-real-key';\n\n$logger = new Logger('ai');\n$logger-\u003epushHandler(new StreamHandler('php://stdout'));\n\n$ai = new AiGenerateImageByReference($apiKey, $logger);\n\n$generatedImageBase64 = $ai\n    -\u003esetStyleImage('style.png')\n    -\u003eaddContentImage('tyna.png', 'girl named Tina')\n    -\u003eaddContentImage('fredy.png', 'boy named Fredy')\n    -\u003egenerate('Fredy and Tina in a park on a sunny day with blue sky – Fredy is riding a bicycle');\n\nif ($generatedImageBase64) {\n    file_put_contents('output.png', base64_decode($generatedImageBase64));\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkdosiodjinud%2Fai-generate-image-by-reference","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkdosiodjinud%2Fai-generate-image-by-reference","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkdosiodjinud%2Fai-generate-image-by-reference/lists"}