user1443629
user1443629

Reputation: 61

How to open a .ico file in PHP?

I have tried to use php to caculate a image's avarage color. So I use the php function: imagecolorat(), imagecreatefromstring()

This is a part of my code:

$fcontents = file_get_contents($imgname);
$im = @imagecreatefromstring($fcontents);

But I find it can read image successfully except .ico How to deal with it?

Upvotes: 0

Views: 1302

Answers (3)

Paul Dixon
Paul Dixon

Reputation: 301075

Try https://github.com/lordelph/icofileloader

$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');

Upvotes: 1

NiloVelez
NiloVelez

Reputation: 3659

Apparently, it is possible using this class

http://www.phpclasses.org/package/2369-PHP-Extract-graphics-from-ico-files-into-PNG-images.html

Upvotes: 0

QArea
QArea

Reputation: 4981

Function imagecreatefromstring() does not work with .ico - format: imagecreatefromstring() returns an image identifier representing the image obtained from the given image. These types will be automatically detected if your build of PHP supports them: JPEG, PNG, GIF, WBMP, and GD2.

Upvotes: 0

Related Questions