PHPackages                             ohorbatiuk/icofileloader - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. ohorbatiuk/icofileloader

ActiveLibrary[Image &amp; Media](/categories/media)

ohorbatiuk/icofileloader
========================

High quality PHP package for reading and converting any .ico icon file, particularly website favicons

3.0.1(1mo ago)053↑130.8%[1 issues](https://github.com/ohorbatiuk/icofileloader/issues)MITPHPPHP &gt;=8.0.0

Since Jan 20Pushed 1mo agoCompare

[ Source](https://github.com/ohorbatiuk/icofileloader)[ Packagist](https://packagist.org/packages/ohorbatiuk/icofileloader)[ Docs](http://icofileloader.dixo.net/)[ RSS](/packages/ohorbatiuk-icofileloader/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (2)Versions (13)Used By (0)

Elphin IcoFileLoader
====================

[](#elphin-icofileloader)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/c80a28e2971d6047180931b2ec67b4eeaa9de7e587a8a81bc060d06b2b0b35d4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6c6f7264656c70682f69636f66696c656c6f616465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/lordelph/icofileloader)[![Coverage Status](https://camo.githubusercontent.com/eb9ab6072c8d99ab18d7e8f9659f90918e0f56b16900b70891d299a3d7111dd3/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6c6f7264656c70682f69636f66696c656c6f616465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/lordelph/icofileloader/code-structure)[![Quality Score](https://camo.githubusercontent.com/fec6fe58ead8cda50b420a3fe58c3dc05a1c239c2a966e5ab01d6a09e1760f11/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6c6f7264656c70682f69636f66696c656c6f616465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/lordelph/icofileloader)

This package provides a means to load and convert .ico files in a PHP application. It has no dependencies apart from [gd](http://php.net/manual/en/book.image.php)for rendering.

The package has unit tests which verify support for 1bit, 4bit, 8bit, 24bit and 32bit .ico files, and the newer form of .ico files which can included embedded PNG files.

Installation
------------

[](#installation)

For recent php versions (8.\*) IcoFileLoader is available via Composer:

```
composer require lordelph/icofileloader
```

PHP 5.6 - 7.x
=============

[](#php-56---7x)

Earlier versions of php from 5.6 onwards can use version 2 of IcoFileLoader

```
composer require lordelph/icofileloader:2.*
```

PHP 5.4 - 5.5
=============

[](#php-54---55)

If you need to use php5.4 or php5.5, you must install the v1.\* branch

```
composer require lordelph/icofileloader:1.*
```

Usage
-----

[](#usage)

The [IcoFileService](https://github.com/lordelph/icofileloader/blob/master/src/IcoFileService.php) class provides a one-shot method `extractIcon`. This should suit most use-cases where you simply want to get one image out of a .ico file.

It returns an image resource, which you can further manipulate with [GD functions](http://php.net/gd), e.g. save it to a file with [imagepng](http://php.net/imagepng)

For example, here's how you extract a 32x32 transparent image from an ico file:

```
$loader = new Elphin\IcoFileLoader\IcoFileService;
$im = $loader->extractIcon('/path/to/icon.ico', 32, 32);

//$im is a GD image resource, so we could, for example, save this as a PNG
imagepng($im, '/path/to/output.png');
```

### Render with background color

[](#render-with-background-color)

Instead of retaining the alpha channel from the icon, you can render with a background color instead - pass the required color as a renderer option as follows:

```
$im = $loader->extractIcon('/path/to/icon.ico', 32, 32, ['background'=>'#FFFFFF']);
```

### Extract icon at any size

[](#extract-icon-at-any-size)

The `extractIcon` method will try find an image in the icon which is the exact size you request at highest color depth it can find. If it can't, it will resize the best quality image in the icon. So, you can request any size you require...

```
$im = $loader->extractIcon('/path/to/icon.ico', 100, 100);
```

### Extract icon from a URL

[](#extract-icon-from-a-url)

As long you have the PHP [fopen wrappers](http://php.net/manual/en/wrappers.php)installed, you can pass a URL to `extractIcon`

```
$im = $loader->extractIcon('https://assets-cdn.github.com/favicon.ico', 16, 16);
```

### Extract icon from binary data

[](#extract-icon-from-binary-data)

If you already have an ico file held as a binary string, `extractIcon` will cope with that just fine too:

```
$data = file_get_contents('/path/to/icon.ico');
$im = $loader->extractIcon($data, 16, 16);
```

Lower level methods
-------------------

[](#lower-level-methods)

If you want to do more than just extract a single image from an icon, you can use lower level methods of [IcoFileService](https://github.com/lordelph/icofileloader/blob/master/src/IcoFileService.php) to inspect an .ico file and perform multiple renderings.

The `fromFile`, `fromString` and `from` methods will parse an `ico` file and return an [Icon](https://github.com/lordelph/icofileloader/blob/master/src/Icon.php) instance representing an icon and the [images](https://github.com/lordelph/icofileloader/blob/master/src/IconImage.php)it contains.

You can iterate the images in icon, examine them, and render them with `renderImage`

For example, here's how you could extract all the images in an icon and save them as individual files.

```
$icon = $loader->fromFile('/path/to/icon.ico');
foreach ($icon as $idx => $image) {
     $im=$loader->renderImage($image);

     $filename=sprintf('img%d-%dx%d.png', $idx, $image->width, $image->height);
     imagepng($im, $filename);

     printf("rendered %s as %s\n", $image->getDescription(), $filename);
}
```

Internals
---------

[](#internals)

The service is composed of a [parser](https://github.com/lordelph/icofileloader/blob/master/src/IcoParser.php) and a [renderer](https://github.com/lordelph/icofileloader/blob/master/src/GdRenderer.php), which can be injected into the service at runtime if you wanted to override them.

The current [GdRenderer](https://github.com/lordelph/icofileloader/blob/master/src/GdRenderer.php) works by drawing individual pixels for BMP based icon images. This isn't going to be terribly fast. PHP 7.2 will have support for [BMP images](http://php.net/imagecreatefrombmp), and I'll add a renderer which takes advantage of that when it is released.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/lordelph/icofileloader/blob/master/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Paul Dixon](http://blog.dixo.net) - 2017 modernization / update
- [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.

Thanks also to the [PHP League's skeleton project](https://github.com/thephpleague/skeleton) from which this project's structure was derived.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/lordelph/icofileloader/blob/master/LICENCE) for more information.

*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). While these were originally provided on the PHPClasses site under a GPL license, Diogo kindly agreed to allow them to be licensed under an MIT license.*

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance89

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 94% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~374 days

Recently: every ~814 days

Total

10

Last Release

56d ago

Major Versions

0.0.2 → 1.0.0-alpha2017-01-22

1.1.0 → 2.0.02017-05-14

2.0.1 → 3.0.02022-08-19

PHP version history (3 changes)0.0.2PHP &gt;=5.6.0

1.1.0PHP &gt;=5.4.0

3.0.0PHP &gt;=8.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/654fd1947beac77a0431fed8a256e3e1876aa40d520183e6e8ff356640af86ce?d=identicon)[ohorbatiuk](/maintainers/ohorbatiuk)

---

Top Contributors

[![lordelph](https://avatars.githubusercontent.com/u/444004?v=4)](https://github.com/lordelph "lordelph (78 commits)")[![jtojnar](https://avatars.githubusercontent.com/u/705123?v=4)](https://github.com/jtojnar "jtojnar (2 commits)")[![ohorbatiuk](https://avatars.githubusercontent.com/u/11755359?v=4)](https://github.com/ohorbatiuk "ohorbatiuk (2 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

convertconverterconvertorextract-iconfaviconicoico-converterico-to-pngiconicon-converterpngpng-filesconvertextractfaviconiconloadico

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/ohorbatiuk-icofileloader/health.svg)

```
[![Health](https://phpackages.com/badges/ohorbatiuk-icofileloader/health.svg)](https://phpackages.com/packages/ohorbatiuk-icofileloader)
```

###  Alternatives

[lordelph/icofileloader

High quality PHP package for reading and converting any .ico icon file, particularly website favicons

40137.4k](/packages/lordelph-icofileloader)[league/color-extractor

Extract colors from an image as a human would do.

1.3k4.9M19](/packages/league-color-extractor)[chrisjean/php-ico

An easy-to-use library to generate valid ICO files.

232663.6k6](/packages/chrisjean-php-ico)[h4cc/wkhtmltoimage-amd64

Convert html to image using webkit (qtwebkit). Static linked linux binary for amd64 systems.

20311.1M16](/packages/h4cc-wkhtmltoimage-amd64)[jkphl/iconizr

A PHP command line tool for converting SVG images to a set of CSS icons (SVG &amp; PNG, single icons and / or CSS sprites) with support for image optimization and Sass output

4869.0k](/packages/jkphl-iconizr)[h4cc/wkhtmltoimage-i386

Convert html to image using webkit (qtwebkit). Static linked linux binary for i386 systems.

33675.9k5](/packages/h4cc-wkhtmltoimage-i386)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
