{"id":27707684,"url":"https://github.com/swiss-devjoy/laravel-image-transformations","last_synced_at":"2025-04-26T07:55:40.078Z","repository":{"id":288402051,"uuid":"967626035","full_name":"swiss-devjoy/laravel-image-transformations","owner":"swiss-devjoy","description":"Secure Cloudflare-like image transformations with security features to your app","archived":false,"fork":false,"pushed_at":"2025-04-17T10:32:16.000Z","size":43,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-26T07:55:39.389Z","etag":null,"topics":["cloudflare","images","laravel","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swiss-devjoy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":"swiss-devjoy"}},"created_at":"2025-04-16T18:38:39.000Z","updated_at":"2025-04-25T07:43:44.000Z","dependencies_parsed_at":"2025-04-18T00:11:08.888Z","dependency_job_id":"2161a34c-db77-4ba7-b22f-6345eed98390","html_url":"https://github.com/swiss-devjoy/laravel-image-transformations","commit_stats":null,"previous_names":["swiss-devjoy/laravel-image-transformations"],"tags_count":1,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiss-devjoy%2Flaravel-image-transformations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiss-devjoy%2Flaravel-image-transformations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiss-devjoy%2Flaravel-image-transformations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiss-devjoy%2Flaravel-image-transformations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swiss-devjoy","download_url":"https://codeload.github.com/swiss-devjoy/laravel-image-transformations/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250955371,"owners_count":21513497,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["cloudflare","images","laravel","php"],"created_at":"2025-04-26T07:55:39.603Z","updated_at":"2025-04-26T07:55:40.072Z","avatar_url":"https://github.com/swiss-devjoy.png","language":"PHP","funding_links":["https://github.com/sponsors/swiss-devjoy"],"categories":[],"sub_categories":[],"readme":"# Secure Cloudflare-like Image Transformations for your Laravel App\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/swiss-devjoy/laravel-image-transformations.svg?style=flat-square)](https://packagist.org/packages/swiss-devjoy/laravel-image-transformations)\n[![Total Downloads](https://img.shields.io/packagist/dt/swiss-devjoy/laravel-image-transformations.svg?style=flat-square)](https://packagist.org/packages/swiss-devjoy/laravel-image-transformations)\n\nAdd Cloudflare-like image transformations with security features to your app, inspired by [Aaron Francis's image proxy implementation](https://aaronfrancis.com/2025/a-cookieless-cache-friendly-image-proxy-in-laravel-inspired-by-cloudflare-9e95f7e0).\n\n## Features\n\n- Transform images on-the-fly with simple URL parameters\n- Support for various transformations (resize, blur, rotate, brightness, contrast, format conversion, quality)\n- Secure URL signing to prevent abuse\n- Rate limiting option for unsigned URLs to prevent abuse\n- Browser and CDN-friendly caching\n- Zero disk storage for transformed images (HTTP caching only)\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require swiss-devjoy/laravel-image-transformations\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"laravel-image-transformations-config\"\n```\n\n## Configuration\n\nThe package comes with sensible defaults, but you can customize the behavior:\n\n```php\nreturn [\n    // Enable/disable all image transformations\n    'enabled' =\u003e env('IMAGE_TRANSFORMATIONS_ENABLED', true),\n\n    // Cache control headers for browser and CDN caching\n    // Sets 30-day cache with immutable flag to improve performance\n    'cache_control_headers' =\u003e 'public, max-age=2592000, s-maxage=2592000, immutable',\n\n    // URL route prefix for all transformed images\n    // Example: /img/options/path-to-image.jpg\n    'url_prefix' =\u003e '/img',\n\n    // Default compression quality (1-100) for supported formats\n    // Higher values mean better quality but larger file sizes\n    'default_quality' =\u003e 90,\n\n    // Security option 1: Cryptographic URL signing\n    // When enabled, prevents unauthorized image transformations by adding a signature hash to URLs\n    // Example: /img/[signature-hash]/options/path-to-image.jpg\n    'signed_urls' =\u003e true,\n\n    // Security option 2: Rate limiting\n    // Controls the frequency of transformation requests from the same client\n    // Note: Use either signed_urls OR ratelimiter (not both simultaneously)\n    'ratelimiter' =\u003e [\n        // Enable rate limiting for transformation requests\n        // Must be disabled when signed_urls is enabled\n        'enabled' =\u003e false,\n\n        // Cache store for rate limiter counters\n        // File-based store recommended to avoid edge case issues like database locks\n        // Options: 'file', 'redis', 'database', etc. from config('cache.stores')\n        'store' =\u003e env('IMAGE_TRANSFORMATIONS_RATELIMITER_STORE', 'file'),\n\n        // Maximum transformation requests allowed per minute per IP\n        // Adjust based on your application's needs and expected traffic\n        'max_attempts' =\u003e 2,\n    ],\n];\n```\n\n## Usage\n\n### Basic Example\n\nOriginal image reference:\n\n```blade\n\u003cimg src=\"/images/profile.jpg\" width=\"500\" height=\"500\"\u003e\n```\n\nWith transformation:\n```blade\n\u003cimg src=\"{{ transformImage('images/profile.jpg', 'width=300,format=webp,quality=80') }}\" width=\"300\" height=\"300\"\u003e\n```\n\n### Transformation Options\n\n| Option | Description | Example |\n|--------|-------------|---------|\n| `width` | Scale down to specified width (maintains aspect ratio) | `width=300` |\n| `height` | Scale down to specified height (maintains aspect ratio) | `height=200` |\n| `format` | Convert image format | `format=webp` |\n| `quality` | Set compression quality (1-100) | `quality=80` |\n| `blur` | Apply blur effect (1-100) | `blur=10` |\n| `rotate` | Rotate image (degrees) | `rotate=90` |\n| `brightness` | Adjust brightness | `brightness=15` |\n| `contrast` | Adjust contrast | `contrast=25` |\n\n## Security Options\n\n### Option 1: Signed URLs (Recommended)\n\nSecure your transformations with cryptographic signatures:\n\n```php\n// config/image-transformations.php\n'signed_urls' =\u003e true,\n```\n\nThis generates a signed URL like:\n```\n/img/100000b3fe067c19625e10ccb1959320e65a7d34d43d9d4d48d3df95691f6f03/width=300,format=webp,quality=80/images/profile.jpg\n```\n\n### Option 2: Rate Limiting\n\nIf you prefer not to use signatures:\n\n```php\n// config/image-transformations.php\n'signed_urls' =\u003e false,\n'ratelimiter' =\u003e [\n    'enabled' =\u003e true,\n],\n```\n\nDirect URLs:\n```\n/img/width=300,format=webp,quality=80/images/profile.jpg\n```\n\n## Performance Considerations\n\n- Images are transformed on-the-fly\n- No disk storage is used for transformed images\n- HTTP caching with appropriate headers (30 days by default)\n- Works best with CDNs for edge caching\n\n## Example Use Cases\n\n### Responsive Images\n\n```blade\n\u003cpicture\u003e\n    \u003csource srcset=\"{{ transformImage('images/hero.jpg', 'width=1200,format=webp') }}\" media=\"(min-width: 800px)\" type=\"image/webp\"\u003e\n    \u003csource srcset=\"{{ transformImage('images/hero.jpg', 'width=800,format=webp') }}\" media=\"(min-width: 600px)\" type=\"image/webp\"\u003e\n    \u003cimg src=\"{{ transformImage('images/hero.jpg', 'width=400,format=webp') }}\" alt=\"Hero image\"\u003e\n\u003c/picture\u003e\n```\n\n### Creative Effects\n\n```blade\n\u003cimg src=\"{{ transformImage('images/profile.jpg', 'blur=5,contrast=10,brightness=5') }}\" alt=\"Stylized profile\"\u003e\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Dimitri König](https://github.com/dimitri-koenig)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiss-devjoy%2Flaravel-image-transformations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswiss-devjoy%2Flaravel-image-transformations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiss-devjoy%2Flaravel-image-transformations/lists"}