PHPackages                             protonlabs/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. protonlabs/icofileloader

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

protonlabs/icofileloader
========================

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

v2.1.1(12mo ago)025.5k↓25.9%1MITPHPPHP &gt;=8.0CI passing

Since Aug 15Pushed 12mo agoCompare

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

READMEChangelog (2)Dependencies (2)Versions (4)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)

> Fork from  to make it compatible with newer PHP versions

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)

IcoFileLoader is available via Composer:

```
composer require lordelph/icofileloader
```

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

39

—

LowBetter than 86% of packages

Maintenance50

Moderate activity, may be stable

Popularity28

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.4% 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 ~1011 days

Total

2

Last Release

361d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/837170204c2dc6beffb28cfca8ff9036709ac38d5f5f16ab2b8b8a7cb025c089?d=identicon)[BafS](/maintainers/BafS)

---

Top Contributors

[![lordelph](https://avatars.githubusercontent.com/u/444004?v=4)](https://github.com/lordelph "lordelph (70 commits)")[![BafS](https://avatars.githubusercontent.com/u/588205?v=4)](https://github.com/BafS "BafS (8 commits)")[![jtojnar](https://avatars.githubusercontent.com/u/705123?v=4)](https://github.com/jtojnar "jtojnar (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

convertextractfaviconiconloadico

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[lordelph/icofileloader

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

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

Extract colors from an image as a human would do.

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

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

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

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

20110.7M15](/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.

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

PHPackages © 2026

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