如何在PHP中打开.ico文件?

时间:2013-01-27 11:47:34

标签: php

我曾试图用PHP来计算图像的平均颜色。 所以我使用php函数:imagecolorat()imagecreatefromstring()

这是我的代码的一部分:

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

但我发现它可以成功读取图像,除了.ico 怎么处理呢?

3 个答案:

答案 0 :(得分:1)

尝试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');

答案 1 :(得分:0)

函数imagecreatefromstring()不能与.ico格式一起使用:imagecreatefromstring()返回一个图像标识符,表示从给定图像中获取的图像。如果你的PHP版本支持它们,将自动检测这些类型:JPEG,PNG,GIF,WBMP和GD2。

答案 2 :(得分:0)