{"id":14109487,"url":"https://github.com/spatie/laravel-image-optimizer","last_synced_at":"2025-05-13T00:19:09.125Z","repository":{"id":49767447,"uuid":"96563589","full_name":"spatie/laravel-image-optimizer","owner":"spatie","description":"Optimize images in your Laravel app","archived":false,"fork":false,"pushed_at":"2025-05-12T11:51:44.000Z","size":192,"stargazers_count":1255,"open_issues_count":0,"forks_count":116,"subscribers_count":32,"default_branch":"main","last_synced_at":"2025-05-13T00:19:07.717Z","etag":null,"topics":["image","laravel","optimize","performance","php"],"latest_commit_sha":null,"homepage":"https://spatie.be/opensource/laravel","language":"PHP","has_issues":false,"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/spatie.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},"funding":{"custom":"https://spatie.be/open-source/support-us"}},"created_at":"2017-07-07T18:03:57.000Z","updated_at":"2025-05-12T11:51:40.000Z","dependencies_parsed_at":"2023-02-16T06:46:14.851Z","dependency_job_id":"2e4c0ee1-d358-4989-b823-00aa5f974c19","html_url":"https://github.com/spatie/laravel-image-optimizer","commit_stats":{"total_commits":154,"total_committers":26,"mean_commits":5.923076923076923,"dds":"0.36363636363636365","last_synced_commit":"d6028e3c7654cade3a6502978692f4dcdcf9d8e6"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-image-optimizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-image-optimizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-image-optimizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-image-optimizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/laravel-image-optimizer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843419,"owners_count":21972908,"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":["image","laravel","optimize","performance","php"],"created_at":"2024-08-14T10:02:20.463Z","updated_at":"2025-05-13T00:19:09.096Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://spatie.be/open-source/support-us"],"categories":["PHP"],"sub_categories":[],"readme":"# Optimize images in your Laravel app\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-image-optimizer.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-image-optimizer)\n![Tests](https://github.com/spatie/laravel-image-optimizer/actions/workflows/run-tests.yml/badge.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-image-optimizer.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-image-optimizer)\n\nThis package is the Laravel 6.0 and up specific integration of [spatie/image-optimizer](https://github.com/spatie/image-optimizer). It can optimize PNGs, JPGs, SVGs and GIFs by running them through a chain of various [image optimization tools](https://github.com/spatie/image-optimizer#optimization-tools). The package will automatically detect which optimization binaries are installed on your system and use them.\n\nHere's how you can use it:\n\n```php\nuse ImageOptimizer;\n\n// the image will be replaced with an optimized version which should be smaller\nImageOptimizer::optimize($pathToImage);\n\n// if you use a second parameter the package will not modify the original\nImageOptimizer::optimize($pathToImage, $pathToOptimizedImage);\n```\n\nYou don't like facades you say? No problem! Just resolve a configured instance of `Spatie\\ImageOptimizer\\OptimizerChain` out of the container:\n\n```php\napp(Spatie\\ImageOptimizer\\OptimizerChain::class)-\u003eoptimize($pathToImage);\n```\n\nThe package also contains [a middleware](https://github.com/spatie/laravel-image-optimizer/blob/master/README.md#using-the-middleware) to automatically optimize all images in an request.\n\nDon't use Laravel you say? No problem! Just use the underlying [spatie/image-optimizer](https://github.com/spatie/image-optimizer) directly.\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-image-optimizer.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/laravel-image-optimizer)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/laravel-image-optimizer\n```\n\nThe package will automatically register itself.\n\nThe package uses a bunch of binaries to optimize images. To learn which ones on how to install them, head over to the [optimization tools section](https://github.com/spatie/image-optimizer#optimization-tools) in the readme of the underlying image-optimizer package. That readme also contains info on [what these tools will do to your images](https://github.com/spatie/image-optimizer#which-tools-will-do-what).\n\nThe package comes with some sane defaults to optimize images. You can modify that configuration by publishing the config file.\n\n```bash\nphp artisan vendor:publish --provider=\"Spatie\\LaravelImageOptimizer\\ImageOptimizerServiceProvider\"\n```\n\nThis is the contents of the `config/image-optimizer` file that will be published:\n\n```php\nuse Spatie\\ImageOptimizer\\Optimizers\\Svgo;\nuse Spatie\\ImageOptimizer\\Optimizers\\Optipng;\nuse Spatie\\ImageOptimizer\\Optimizers\\Gifsicle;\nuse Spatie\\ImageOptimizer\\Optimizers\\Pngquant;\nuse Spatie\\ImageOptimizer\\Optimizers\\Jpegoptim;\nuse Spatie\\ImageOptimizer\\Optimizers\\Cwebp;\n\nreturn [\n    /**\n     * When calling `optimize` the package will automatically determine which optimizers\n     * should run for the given image.\n     */\n    'optimizers' =\u003e [\n\n        Jpegoptim::class =\u003e [\n            '-m85', // set maximum quality to 85%\n            '--strip-all',  // this strips out all text information such as comments and EXIF data\n            '--all-progressive'  // this will make sure the resulting image is a progressive one\n        ],\n\n        Pngquant::class =\u003e [\n            '--force' // required parameter for this package\n        ],\n\n        Optipng::class =\u003e [\n            '-i0', // this will result in a non-interlaced, progressive scanned image\n            '-o2',  // this set the optimization level to two (multiple IDAT compression trials)\n            '-quiet' // required parameter for this package\n        ],\n\n        Svgo::class =\u003e [\n            '--disable=cleanupIDs' // disabling because it is known to cause trouble\n        ],\n\n        Gifsicle::class =\u003e [\n            '-b', // required parameter for this package\n            '-O3' // this produces the slowest but best results\n        ],\n        \n        Cwebp::class =\u003e [\n            '-m 6', // for the slowest compression method in order to get the best compression.\n            '-pass 10', // for maximizing the amount of analysis pass.\n            '-mt', // multithreading for some speed improvements.\n            '-q 90', //quality factor that brings the least noticeable changes.\n        ],\n    ],\n\n    /**\n     * The maximum time in seconds each optimizer is allowed to run separately.\n     */\n    'timeout' =\u003e 60,\n\n    /**\n     * If set to `true` all output of the optimizer binaries will be appended to the default log.\n     * You can also set this to a class that implements `Psr\\Log\\LoggerInterface`.\n     */\n    'log_optimizer_activity' =\u003e false,\n];\n```\n\nIf you want to automatically optimize images that get uploaded to your application add the `\\Spatie\\LaravelImageOptimizer\\Middlewares\\OptimizeImages::class` in the http kernel.\n\n```php\n// app/Http/Kernel.php\nprotected $middlewareAliases = [\n   ...\n   'optimizeImages' =\u003e \\Spatie\\LaravelImageOptimizer\\Middlewares\\OptimizeImages::class,\n];\n```\n\n## Usage\n\nYou can resolve a configured instance of `Spatie\\ImageOptimizer\\OptimizerChain` out of the container:\n\n```php\n// the image will be replaced with an optimized version which should be smaller\napp(Spatie\\ImageOptimizer\\OptimizerChain::class)-\u003eoptimize($pathToImage);\n\n// if you use a second parameter the package will not modify the original\napp(Spatie\\ImageOptimizer\\OptimizerChain::class)-\u003eoptimize($pathToImage, $pathToOptimizedImage);\n```\n\n### Using the facade\n\n```php\nuse ImageOptimizer;\n\n// the image will be replaced with an optimized version which should be smaller\nImageOptimizer::optimize($pathToImage);\n\n// if you use a second parameter the package will not modify the original\nImageOptimizer::optimize($pathToImage, $pathToOptimizedImage);\n```\n\nYou don't like facades you say? No problem! Just resolve a configured instance of `Spatie\\ImageOptimizer\\OptimizerChain` out of the container:\n\n```php\napp(Spatie\\ImageOptimizer\\OptimizerChain::class)-\u003eoptimize($pathToImage);\n```\n\n### Using the middleware\n\nAll images that in requests to routes that use the `optimizeImages`-middleware will be optimized automatically.\n\n```php\nRoute::middleware('optimizeImages')-\u003egroup(function () {\n    // all images will be optimized automatically\n    Route::post('upload-images', 'UploadController@index');\n});\n```\n\n### Adding your own optimizers\n\nTo learn how to create your own optimizer read the [\"Writing custom optimizers\" section](https://github.com/spatie/image-optimizer#writing-a-custom-optimizers) in the readme of the underlying [spatie/image-optimizer](https://github.com/spatie/image-optimizer#writing-a-custom-optimizers) package.\n\nYou can add the fully qualified classname of your optimizer as a key in the `optimizers` array in the config file.\n\n## Example conversions\n\nHere are some [example conversions](https://github.com/spatie/image-optimizer#example-conversions) that were made by the optimizer.\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Testing\n\n``` bash\ncomposer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Postcardware\n\nYou're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.\n\nOur address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.\n\nWe publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\nThe idea of a middleware that optimizes all files in a request is taken from [approached/laravel-image-optimizer](https://github.com/approached/laravel-image-optimizer).\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%2Fspatie%2Flaravel-image-optimizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Flaravel-image-optimizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-image-optimizer/lists"}