{"id":33997247,"url":"https://github.com/lordelph/icofileloader","last_synced_at":"2025-12-13T08:55:50.827Z","repository":{"id":16175068,"uuid":"79501980","full_name":"lordelph/icofileloader","owner":"lordelph","description":"A high quality PHP package for reading and converting any .ico icon file, particularly website favicons","archived":false,"fork":false,"pushed_at":"2022-08-19T19:13:11.000Z","size":529,"stargazers_count":34,"open_issues_count":6,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-09T17:12:44.665Z","etag":null,"topics":["extract-icon","favicon","ico","ico-files","php"],"latest_commit_sha":null,"homepage":"http://icofileloader.dixo.net/","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/lordelph.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-19T22:32:30.000Z","updated_at":"2024-04-05T09:34:10.000Z","dependencies_parsed_at":"2022-08-30T21:11:24.482Z","dependency_job_id":null,"html_url":"https://github.com/lordelph/icofileloader","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/lordelph/icofileloader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lordelph%2Ficofileloader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lordelph%2Ficofileloader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lordelph%2Ficofileloader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lordelph%2Ficofileloader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lordelph","download_url":"https://codeload.github.com/lordelph/icofileloader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lordelph%2Ficofileloader/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27702854,"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","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["extract-icon","favicon","ico","ico-files","php"],"created_at":"2025-12-13T08:55:48.948Z","updated_at":"2025-12-13T08:55:50.806Z","avatar_url":"https://github.com/lordelph.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Elphin IcoFileLoader\r\n====================\r\n[![Software License][ico-license]](LICENSE.md)\r\n[![Build Status][ico-travis]][link-travis]\r\n[![Coverage Status][ico-scrutinizer]][link-scrutinizer]\r\n[![Quality Score][ico-code-quality]][link-code-quality]\r\n\r\n\r\nThis package provides a means to load and convert .ico files in a PHP application. \r\nIt has no dependencies apart from [gd](http://php.net/manual/en/book.image.php) \r\nfor rendering.\r\n\r\nThe package has unit tests which verify support for 1bit, 4bit, 8bit, 24bit and 32bit\r\n.ico files, and the newer form of .ico files which can included embedded PNG files.\r\n\r\n## Installation\r\n\r\nFor recent php versions (8.*) IcoFileLoader is available via Composer:\r\n\r\n```bash\r\ncomposer require lordelph/icofileloader\r\n```\r\n\r\n# PHP 5.6 - 7.x\r\n\r\nEarlier versions of php from 5.6 onwards can use version 2 of IcoFileLoader\r\n\r\n```bash\r\ncomposer require lordelph/icofileloader:2.*\r\n```\r\n\r\n# PHP 5.4 - 5.5\r\n\r\nIf you need to use php5.4 or php5.5, you must install the v1.* branch\r\n\r\n```bash\r\ncomposer require lordelph/icofileloader:1.*\r\n```\r\n\r\n## Usage\r\nThe [IcoFileService][class-icofileservice] class provides a one-shot method \r\n`extractIcon`. This should suit most use-cases where you simply want to get one \r\nimage out of a .ico file. \r\n\r\nIt returns an image resource, which you can further manipulate with \r\n[GD functions](http://php.net/gd), e.g. save it to a file with \r\n[imagepng](http://php.net/imagepng)\r\n\r\nFor example, here's how you extract a 32x32 transparent image from an ico file:\r\n\r\n```php\r\n$loader = new Elphin\\IcoFileLoader\\IcoFileService;\r\n$im = $loader-\u003eextractIcon('/path/to/icon.ico', 32, 32);\r\n\r\n//$im is a GD image resource, so we could, for example, save this as a PNG\r\nimagepng($im, '/path/to/output.png');\r\n```\r\n\r\n### Render with background color\r\n\r\nInstead of retaining the alpha channel from the icon, you can render with a \r\nbackground color instead - pass the required color as a renderer option as follows:\r\n\r\n```php\r\n$im = $loader-\u003eextractIcon('/path/to/icon.ico', 32, 32, ['background'=\u003e'#FFFFFF']);\r\n```\r\n\r\n### Extract icon at any size\r\n\r\nThe `extractIcon` method will try find an image in the icon which is the exact\r\nsize you request at highest color depth it can find. If it can't, it will resize the\r\nbest quality image in the icon. So, you can request any size you require...\r\n\r\n```php\r\n$im = $loader-\u003eextractIcon('/path/to/icon.ico', 100, 100);\r\n```\r\n\r\n### Extract icon from a URL\r\n\r\nAs long you have the PHP [fopen wrappers](http://php.net/manual/en/wrappers.php) \r\ninstalled, you can pass a URL to `extractIcon`\r\n\r\n```php\r\n$im = $loader-\u003eextractIcon('https://assets-cdn.github.com/favicon.ico', 16, 16);\r\n```\r\n\r\n### Extract icon from binary data\r\n\r\nIf you already have an ico file held as a binary string, `extractIcon` will cope \r\nwith that just fine too:\r\n```php\r\n$data = file_get_contents('/path/to/icon.ico');\r\n$im = $loader-\u003eextractIcon($data, 16, 16);\r\n```\r\n\r\n## Lower level methods\r\n\r\nIf you want to do more than just extract a single image from an icon, you can use \r\nlower level methods of [IcoFileService][class-icofileservice] to inspect an .ico \r\nfile and perform multiple renderings.\r\n\r\nThe `fromFile`, `fromString` and `from` methods will parse an `ico` file and return\r\nan [Icon][class-icon] instance representing an icon and the [images][class-image] \r\nit contains.\r\n \r\nYou can iterate the images in icon, examine them, and render them with `renderImage`\r\n\r\nFor example, here's how you could extract all the images in an icon and save them\r\nas individual files.\r\n\r\n```php\r\n$icon = $loader-\u003efromFile('/path/to/icon.ico');\r\nforeach ($icon as $idx =\u003e $image) {\r\n     $im=$loader-\u003erenderImage($image);\r\n     \r\n     $filename=sprintf('img%d-%dx%d.png', $idx, $image-\u003ewidth, $image-\u003eheight);\r\n     imagepng($im, $filename);\r\n     \r\n     printf(\"rendered %s as %s\\n\", $image-\u003egetDescription(), $filename);\r\n}\r\n```\r\n\r\n## Internals\r\n\r\nThe service is composed of a [parser][class-parser] and a [renderer][class-renderer],\r\nwhich can be injected into the service at runtime if you wanted to override them.\r\n\r\nThe current [GdRenderer][class-renderer] works by drawing individual pixels for BMP\r\nbased icon images. This isn't going to be terribly fast. PHP 7.2 will have support\r\nfor [BMP images](http://php.net/imagecreatefrombmp), and I'll add a renderer which \r\ntakes advantage of that when it is released.\r\n\r\n\r\n## Testing\r\n\r\n``` bash\r\n$ composer test\r\n```\r\n\r\n## Contributing\r\n\r\nPlease see [CONTRIBUTING](https://github.com/lordelph/icofileloader/blob/master/CONTRIBUTING.md) for details.\r\n\r\n\r\n## Credits\r\n\r\n- [Paul Dixon](http://blog.dixo.net) - 2017 modernization / update\r\n- [Diogo Resende](https://www.phpclasses.org/package/2369-PHP-Extract-graphics-from-ico-files-into-PNG-images.html). Original author of 2005 library this was derived from.\r\n\r\nThanks also to the [PHP League's skeleton project](https://github.com/thephpleague/skeleton) from which this project's structure was derived.\r\n\r\n## License\r\n\r\nThe MIT License (MIT). Please see [License File](https://github.com/lordelph/icofileloader/blob/master/LICENCE) for more information.\r\n\r\n*Note: this was based on some classes originally written in 2005 by [Diogo Resende](https://www.phpclasses.org/package/2369-PHP-Extract-graphics-from-ico-files-into-PNG-images.html). \r\nWhile these were originally provided on the PHPClasses site under a GPL license,\r\nDiogo kindly agreed to allow them to be licensed under an MIT license.*\r\n\r\n[class-icofileservice]: https://github.com/lordelph/icofileloader/blob/master/src/IcoFileService.php\r\n[class-icon]: https://github.com/lordelph/icofileloader/blob/master/src/Icon.php\r\n[class-image]: https://github.com/lordelph/icofileloader/blob/master/src/IconImage.php\r\n[class-parser]: https://github.com/lordelph/icofileloader/blob/master/src/IcoParser.php\r\n[class-renderer]: https://github.com/lordelph/icofileloader/blob/master/src/GdRenderer.php\r\n\r\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\r\n[ico-travis]: https://img.shields.io/travis/lordelph/icofileloader/master.svg?style=flat-square\r\n[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/lordelph/icofileloader.svg?style=flat-square\r\n[ico-code-quality]: https://img.shields.io/scrutinizer/g/lordelph/icofileloader.svg?style=flat-square\r\n[ico-downloads]: https://img.shields.io/packagist/dt/lordelph/icofileloader.svg?style=flat-square\r\n\r\n[link-packagist]: https://packagist.org/packages/lordelph/icofileloader\r\n[link-travis]: https://travis-ci.org/lordelph/icofileloader\r\n[link-scrutinizer]: https://scrutinizer-ci.com/g/lordelph/icofileloader/code-structure\r\n[link-code-quality]: https://scrutinizer-ci.com/g/lordelph/icofileloader\r\n[link-downloads]: https://packagist.org/packages/lordelph/icofileloader\r\n[link-author]: https://github.com/lordelph\r\n[link-contributors]: ../../contributors\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flordelph%2Ficofileloader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flordelph%2Ficofileloader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flordelph%2Ficofileloader/lists"}