使用 PHP 将 ICO 转换为 PNG 时出现问题
上下文:Favicon
我正在编写一个 WordPress 插件来下载 favicon 并将其转换为 png:
http://plugins.trac.wordpress.org/browser/wp-favicons/trunk (GPL2)
图标Lib
- 我需要一个 ICO 到 PNG 转换库,它不从磁盘读取文件,而是从字符串读取文件。
- 我还需要对用户的广泛支持,所以不是一个编译后的 php,其参数不是大多数普通 WordPress 用户所拥有的,
- 我目前正在使用这个: http://www.phpclasses.org/package/2369-PHP-Extract-graphics-from-ico -files-into-PNG-images.html
问题
5000 个图标中有 1 个(其他都正常...) XOR 功能出现问题。请参阅此处的第 296 行: http://plugins.trac.wordpress.org/browser/wp-favicons/trunk/plugins/filters/inc/class.ico .php (注意:未初始化的字符串偏移量:64)因此预期的字符串太小。
示例
此图标就是一个示例:单击此处查看(导航至 slatch.com)
问题
有人知道如何解决这个问题吗?或者知道另一个好的 PHP 图标类,它可以让我通过 get_as_string 而不是 get_from_file 读取 .ico (各种),哪个更好?
PS
我已经读过:
Context: Favicons
I am writing a WordPress plugin to download favicons and also convert them to png:
http://plugins.trac.wordpress.org/browser/wp-favicons/trunk ( GPL2)
Icon Lib
- I needed to have an ICO to PNG conversion Library that does not read files from disk but from strings.
- I also need broad support for users so not a compiled php with a parameter that not most of the general WordPress users have
- I am currently using this one: http://www.phpclasses.org/package/2369-PHP-Extract-graphics-from-ico-files-into-PNG-images.html
Problem
In 1 out of 5.000 icons (the others work ok...) a problem occurs with the XOR functionality. See line 296 here: http://plugins.trac.wordpress.org/browser/wp-favicons/trunk/plugins/filters/inc/class.ico.php (Notice: Uninitialized string offset: 64) So the string expected is too small.
Example
An example is this icon: click here to see (navigates to slatch.com)
Question
Does anybody know how to fix this? OR knows another good PHP Icon Class that lets me read .ico (all sorts of) via get_as_string instead of get_from_file which is better?
PS
I already read:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您发布的示例图标是单色的 (1 BPP)。该库可能不支持如此低的颜色深度。
The example icon you posted is monochrome (1 BPP). Its possible the library does not support such a low color depth.
我编写了一个经过完全单元测试的包,用于读取支持 1bpp 图像(以及嵌入式 PNG)的 .ico 文件 - 可以在此处获取 https://github.com/lordelph/icofileloader
问题中问题 .ico 的链接已失效,但如果有人遇到类似问题,我很乐意修复该包。
I've written a fully unit tested package for reading .ico files which supports 1bpp images (as well as embedded PNGs) - it's available here https://github.com/lordelph/icofileloader
The link to the problem .ico in the question is dead, but I'm happy to fix the package if anyone comes across a similar problem.
@edelwater
我可能弄错了,但新一代的ICO文件不是真的是具有不同扩展名的PNG吗?这就是我过去创建它们的方式。我可以理解将 jpeg 等其他格式转换为 png,然后更改扩展名。
http://en.wikipedia.org/wiki/Favicon#Standardization
http://en.wikipedia.org/wiki/ICO_(file_format)#PNG_format
这并不是一个答案,而是一个参考。
@edelwater
I might be mistaken, but isn't the new generation of ICO files really PNG's with a different extension? That's how I have created them in the past. I could understand converting other formats like jpeg to png and then changing the extension.
http://en.wikipedia.org/wiki/Favicon#Standardization
http://en.wikipedia.org/wiki/ICO_(file_format)#PNG_format
This isn't meant to be a answer but a reference.
该类支持 1 bpp(单色)ico 文件。然而它有一个错误。它无法考虑每个图像行到 4 字节(32 位)边界的填充,因此宽度小于 32 像素的图标无法正确解码。
我将修复此问题供我自己使用,但我不确定如何处理它。在这里发布补丁吗?
The class supports 1 bpp (monochrome) ico files. However there is a bug with it. It fails to account for the padding of each image line to a 4 byte (32 bit) boundary, hence icons less wide than 32 pixels are not properly decoded.
I'm going to fix this for my own use, but I'm not sure what to do with it. Post a patch here?