PHP 中如何检测 *.ico 文件是否为有效图标

发布于 2024-09-12 00:29:10 字数 70 浏览 1 评论 0原文

我想测试 *.ico 图像是否是 PHP 中的有效图标。我尝试使用 getimagesize 函数,但它不支持 ICO 文件。

I would like to test if *.ico images are valid icons in PHP. I tried to use getimagesize function but it doesn't support ICO files.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夏了南城 2024-09-19 00:29:10

http://en.wikipedia.org/wiki/ICO_(file_format)

图标必须以“0x00 0x00 0x01 0x00”字节开头,对于简单测试来说应该足够了。

http://en.wikipedia.org/wiki/ICO_(file_format)

icon must start with the '0x00 0x00 0x01 0x00' bytes, it shall be enough for simple test.

帅气尐潴 2024-09-19 00:29:10

ico 文件主要是图像文件,如果您将 jpeg 或 gif/png 更改为 ico 扩展名,它可以正常工作,因此如果您保持图像类型检查,它将完成工作

ico files are mainly image files, if you change a jpeg or gif/png into ico extension it works fine,so if you keep image type cheking it will do the job

染柒℉ 2024-09-19 00:29:10

https://github.com/lordelph/icofileloader 是一个用于读取 .ico 文件的可安装包。要检查和检查 .ico 文件,您可以调整此示例:

$loader = new Elphin\IcoFileLoader\IcoFileService;

//parse ico file
try {
    $icon = $loader->fromFile('/path/to/icon.ico');

    //we can iterate over the images in the icon
    foreach ($icon as $idx => $image) {
        printf("image %d is %s\n", $idx, $image->getDescription());
    }
}
catch (\Exception $e) {
     echo "not a valid .ico file";
}

https://github.com/lordelph/icofileloader is a composer-installable package for reading .ico files. To check and inspect an .ico file, you could adapt this sample:

$loader = new Elphin\IcoFileLoader\IcoFileService;

//parse ico file
try {
    $icon = $loader->fromFile('/path/to/icon.ico');

    //we can iterate over the images in the icon
    foreach ($icon as $idx => $image) {
        printf("image %d is %s\n", $idx, $image->getDescription());
    }
}
catch (\Exception $e) {
     echo "not a valid .ico file";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文