{"id":13545657,"url":"https://github.com/psliwa/image-optimizer","last_synced_at":"2025-05-14T19:02:06.418Z","repository":{"id":19323588,"uuid":"22561944","full_name":"psliwa/image-optimizer","owner":"psliwa","description":"Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.","archived":false,"fork":false,"pushed_at":"2023-11-20T12:10:29.000Z","size":671,"stargazers_count":902,"open_issues_count":10,"forks_count":138,"subscribers_count":35,"default_branch":"master","last_synced_at":"2024-05-17T08:42:26.260Z","etag":null,"topics":["gif","image","image-optimization","jpegoptim","jpg","optipng","performance","php","png","pngquant"],"latest_commit_sha":null,"homepage":null,"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/psliwa.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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":{"github":["psliwa"],"custom":"https://www.paypal.me/psliwa"}},"created_at":"2014-08-03T00:20:44.000Z","updated_at":"2024-06-18T10:53:56.455Z","dependencies_parsed_at":"2024-06-18T10:53:56.102Z","dependency_job_id":"4e7750bc-daff-4852-b51a-776465941e1b","html_url":"https://github.com/psliwa/image-optimizer","commit_stats":{"total_commits":56,"total_committers":15,"mean_commits":"3.7333333333333334","dds":0.5,"last_synced_commit":"5cfbb17c5448f833c564aab42133988835dbce99"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psliwa%2Fimage-optimizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psliwa%2Fimage-optimizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psliwa%2Fimage-optimizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psliwa%2Fimage-optimizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/psliwa","download_url":"https://codeload.github.com/psliwa/image-optimizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837049,"owners_count":21169373,"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":["gif","image","image-optimization","jpegoptim","jpg","optipng","performance","php","png","pngquant"],"created_at":"2024-08-01T11:01:08.463Z","updated_at":"2025-04-14T06:40:29.727Z","avatar_url":"https://github.com/psliwa.png","language":"PHP","funding_links":["https://github.com/sponsors/psliwa","https://www.paypal.me/psliwa"],"categories":["PHP","图像 Imagery","目录","Table of Contents","图像( Imagery )"],"sub_categories":["图像 Imagery","Imagery","Globalization"],"readme":"# Image Optimizer [![Build Status](https://app.travis-ci.com/psliwa/image-optimizer.svg?branch=master)](https://app.travis-ci.com/github/psliwa/image-optimizer)\n\nThis library is handy and very easy to use optimizer for image files. It uses [optipng][2], [pngquant][1], [jpegoptim][6], [svgo][9] and few more libraries,\nso before use it you should install proper libraries on your server. Project contains Vagrantfile that defines testing\nvirtual machine with all libraries installed, so you can check Vagrantfile how to install all those stuff.\n\nThanks to ImageOptimizer and libraries that it uses, your image files can be **10%-70% smaller**.\n\n# Installation\n\nUsing composer:\n\n    composer require ps/image-optimizer\n\n# Basic usage\n\n```php\n$factory = new \\ImageOptimizer\\OptimizerFactory();\n$optimizer = $factory-\u003eget();\n\n$filepath = /* path to image */;\n\n$optimizer-\u003eoptimize($filepath);\n//optimized file overwrites original one\n```\n\n# Configuration\n\nBy default optimizer does not throw any exception, if file can not be optimized or optimizing library for given file is\nnot installed, optimizer will not touch original file. This behaviour is ok when you want to eventually optimize files\nuploaded by user. When in your use case optimization fault should cause exception, `ignore_errors` option was created\nespecially for you.\n\nThis library is very smart, you do not have to configure paths to all binaries of libraries that are used by ImageOptimizer,\nlibrary will be looking for those binaries in few places, so if binaries are placed in standard places, it will be found\nautomatically.\n\nSupported options:\n\n* `ignore_errors` (default: true)\n* `single_optimizer_timeout_in_seconds` (default: 60) - useful when you\n  want to have control how long optimizing lasts. For example in some\n  cases optimizing may not be worth when it takes big amount of time.\n  Pass `null` in order to turn off timeout.\n* `output_filepath_pattern` (default: `%basename%/%filename%%ext%`) -\n  destination where optimized file will be stored. By default it\n  overrides original file. There are 3 placehoders: `%basename%`,\n  `%filename%` (without extension and dot) and `%ext%` (extension with\n  dot) which will be replaced by values from original file.\n* `execute_only_first_png_optimizer` (default: true) - execute the first\n  successful or all `png` optimizers\n* `execute_only_first_jpeg_optimizer` (default: true) - execute the first successful or all `jpeg` optimizers\n* `optipng_options` (default: `array('-i0', '-o2', '-quiet')`) - an array of arguments to pass to the library\n* `pngquant_options` (default: `array('--force')`)\n* `pngcrush_options` (default: `array('-reduce', '-q', '-ow')`)\n* `pngout_options` (default: `array('-s3', '-q', '-y')`)\n* `advpng_options` (default: `array('-z', '-4', '-q')`)\n* `gifsicle_options` (default: `array('-b', '-O5')`)\n* `jpegoptim_options` (default: `array('--strip-all', '--all-progressive')`)\n* `jpegtran_options` (default: `array('-optimize', '-progressive')`)\n* `svgo_options` (default: `array('--disable=cleanupIDs')`)\n* `custom_optimizers` (default `array()`)\n* `optipng_bin` (default: will be guessed) - you can enforce paths to binaries, but by default it will be guessed\n* `pngquant_bin`\n* `pngcrush_bin`\n* `pngout_bin`\n* `advpng_bin`\n* `gifsicle_bin`\n* `jpegoptim_bin`\n* `jpegtran_bin`\n* `svgo_bin`\n\nYou can pass array of options as first argument of `ImageOptimizer\\OptimizerFactory` constructor. Second argument is\noptionally `Psr\\LoggerInterface`.\n\n```php\n$factory = new \\ImageOptimizer\\OptimizerFactory(array('ignore_errors' =\u003e false), $logger);\n```\n\n# Supported optimizers\n\n* default (`smart`) - it guess file type and choose optimizer for this file type\n* `png` - chain of optimizers for png files, by default it uses `pngquant` and `optipng`. `pngquant` is lossy optimization\n* `jpg` - first of two optimizations will be executed: `jpegtran` or `jpegoptim`\n* `gif` - alias to `gifsicle`\n* `pngquant` - [homepage][1]\n* `optipng` - [homepage][2]\n* `pngcrush` - [homepage][3]\n* `pngout` - [homepage][4]\n* `advpng` - [homepage][5]\n* `jpegtran` - [homepage][6]\n* `jpegoptim` - [homepage][7]\n* `gifsicle` - [homepage][8]\n* `svgo` - [homepage][9]\n\nYou can obtain concrete optimizer by passing his name to `ImageOptimizer\\OptimizerFactory`::`get` method:\n\n```php\n//default optimizer is `smart`\n$optimizer = $factory-\u003eget();\n\n//png optimizer\n$pngOptimizer = $factory-\u003eget('png');\n\n//jpegoptim optimizer etc.\n$jpgOptimizer = $factory-\u003eget('jpegoptim');\n```\n\n# Custom optimizers\n\nYou can easily define custom optimizers:\n\n```php\n$factory = new \\ImageOptimizer\\OptimizerFactory(array('custom_optimizers' =\u003e array(\n    'some_optimizier' =\u003e array(\n        'command' =\u003e 'some_command',\n        'args' =\u003e array('-some-flag')\n    )\n)), $logger);\n```\n\nAnd then usage:\n\n```php\n$customOptimizer = $factory-\u003eget('some_optimizier');\n```\n\n# I got \"All optimizers failed to optimize the file\"\n\nProbably you don't have required optimazers installed. Let's have a look\nat `Vagrantfile` file in order to see an example how to install those\ncommands.\n\nIn order to see all intermediate errors, you can use logger (be default\n`NullLogger` is used, so logs are not available):\n\n```php\nclass StdoutLogger extends \\Psr\\Log\\AbstractLogger { \n    public function log($level, $message, array $context = array()) { \n        echo $message.\"\\n\"; \n    }\n}\n\n$factory = new \\ImageOptimizer\\OptimizerFactory(array(), new StdoutLogger());\n\n$factory-\u003eget()-\u003eoptimize('yourfile.jpg');\n\n// and have a look at stdout\n```\n\n# License\n\n**MIT**\n\n[1]: http://pngquant.org/\n[2]: http://optipng.sourceforge.net/\n[3]: http://pmt.sourceforge.net/pngcrush/\n[4]: http://www.jonof.id.au/kenutils\n[5]: http://advancemame.sourceforge.net/doc-advpng.html\n[6]: http://jpegclub.org/jpegtran/\n[7]: http://freecode.com/projects/jpegoptim\n[8]: http://www.lcdf.org/gifsicle/\n[9]: https://github.com/svg/svgo\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsliwa%2Fimage-optimizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpsliwa%2Fimage-optimizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsliwa%2Fimage-optimizer/lists"}