{"id":20969871,"url":"https://github.com/ourcodeworld/php-pngquant","last_synced_at":"2025-05-14T11:32:40.526Z","repository":{"id":57034078,"uuid":"79019491","full_name":"ourcodeworld/php-pngquant","owner":"ourcodeworld","description":"A wrapper class to work with pngquant with PHP.","archived":false,"fork":false,"pushed_at":"2017-04-10T21:25:33.000Z","size":8,"stargazers_count":14,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-18T00:44:02.670Z","etag":null,"topics":["composer","php-pngquant","pngquant","wrapper"],"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/ourcodeworld.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-15T09:28:20.000Z","updated_at":"2022-05-24T19:02:31.000Z","dependencies_parsed_at":"2022-08-23T20:50:33.734Z","dependency_job_id":null,"html_url":"https://github.com/ourcodeworld/php-pngquant","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ourcodeworld%2Fphp-pngquant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ourcodeworld%2Fphp-pngquant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ourcodeworld%2Fphp-pngquant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ourcodeworld%2Fphp-pngquant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ourcodeworld","download_url":"https://codeload.github.com/ourcodeworld/php-pngquant/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254131662,"owners_count":22019976,"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":["composer","php-pngquant","pngquant","wrapper"],"created_at":"2024-11-19T03:53:22.234Z","updated_at":"2025-05-14T11:32:39.981Z","avatar_url":"https://github.com/ourcodeworld.png","language":"PHP","readme":"# What is PHP PNGQuant\n\nPHP-PNGQuant is a non-official wrapper for the great [PNGQuant](https://github.com/pornel/pngquant), the command-line utility and a library for lossy compression of PNG images.\n\n# Requirements\n\nYou need `pngquant` accesible from the PATH. If the utility isn't available for any reason, you can change the path to the binary using the `setBinaryPath` method:\n\n```php\n\u003c?php\n\nuse ourcodeworld\\PNGQuant\\PNGQuant;\n\n$instance = new PNGQuant();\n\n// Change the path to the binary of pngquant, for example in windows would be (with an example path):\n$instance-\u003esetBinaryPath(\"C:\\\\Users\\\\sdkca\\\\Desktop\\\\pngquant.exe\")\n    // Other options of PNGQuant here\n    -\u003eexecute();\n```\n\n# Installation\n\nphp-pngquant can be used either with or without Composer.\n\n## With Composer\n\nThe preferred way to use php-pngquant is with Composer. Execute the following command to install this package as a dependency in your project:\n\n```batch\ncomposer require ourcodeworld/php-pngquant\n```\n\n## Without Composer\n\nIf you don't use composer, you can still use the wrapper. Download the [PNGQuant.php](https://github.com/ourcodeworld/php-pngquant/blob/master/src/PNGQuant.php) class from the repository and then use `require_once` to import it in your code:\n\n```php\n\u003c?php\n\nrequire_once(\"PNGQuant.php\");\n\n$instance = new PNGQuant();\n\n// Configuration here ...\n```\n# Example\n\nSave the file directly into a directory with a file name.\n\n```php\n// Include the class\nuse ourcodeworld\\PNGQuant\\PNGQuant;\n\n$instance = new PNGQuant();\n\n// Set the path to the image to compress\n$exit_code = $instance-\u003esetImage(\"/a-folder/image-original.png\")\n    // Set the output filepath\n    -\u003esetOutputImage(\"/a-folder/image-compressed.png\")\n    // Overwrite output file if exists, otherwise pngquant will generate output ...\n    -\u003eoverwriteExistingFile()\n    // As the quality in pngquant isn't fixed (it uses a range)\n    // set the quality between 50 and 80\n    -\u003esetQuality(50,80)\n    // Execute the command\n    -\u003eexecute();\n\n// if exit code is equal to 0 then everything went right !\nif(!$exit_code){\n    echo \"Image succesfully compressed\";\n}else{\n    echo \"Something went wrong (status code $exit_code)  with description: \". $instance-\u003egetErrorTable()[(string) $exit_code];\n}\n```\n\nIf you need the raw data of the image (store the binary data of the compressed image), you can use the `getRawOutput` function:\n\n```php\n// Include the class\nuse ourcodeworld\\PNGQuant\\PNGQuant;\n\n$instance = new PNGQuant();\n\n// Set the path to the image to compress\n$result = $instance-\u003esetImage(\"/a-folder/image-original.png\")\n    // Overwrite output file if exists, otherwise pngquant will generate output ...\n    -\u003eoverwriteExistingFile()\n    // As the quality in pngquant isn't fixed (it uses a range)\n    // set the quality between 50 and 80\n    -\u003esetQuality(50,80)\n    // Retrieve RAW data from pngquant\n    -\u003egetRawOutput();\n\n$exit_code = $result[\"statusCode\"];\n\n\n// if exit code is equal to 0 then everything went right !\nif($exit_code == 0){\n\n    $rawImage = imagecreatefromstring($result[\"imageData\"]);\n\n    // Example Save the PNG Image from the raw data into a file or do whatever you want.\n    // imagepng($rawImage , 'newfile.png');\n\n    echo \"Image succesfully compressed, do something with the raw Data\";\n}else{\n    echo \"Something went wrong (status code $exit_code)  with description: \". $instance-\u003egetErrorTable()[(string) $exit_code];\n}\n```\n\n# Documentation\n\nFor further information and examples of the wrapper, please [visit the official documentation here](http://docs.ourcodeworld.com/projects/php-pngquant).\n\nThe MIT License (MIT)\n=====================\n\nCopyright © 2017 Our Code World\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the “Software”), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fourcodeworld%2Fphp-pngquant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fourcodeworld%2Fphp-pngquant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fourcodeworld%2Fphp-pngquant/lists"}