使用 PHP 将 png 文件转换为 ico
我想创建一个 PHP 脚本,将 png 文件转换为 ico 文件。只用 PHP 可以做到吗?如何 ?
谢谢 !!!
I would like to create a PHP script that convert a png file to an ico file. Is it possible to do it just with PHP ? How ?
Thanks !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
最近上传的 https://github.com/chrisbliss18/php-ico 创建有效的 ICO 文件,包括仅使用 PHP 和 GD 库即可实现 PNG 文件和其他文件格式的多个嵌入分辨率。
The recently uploaded https://github.com/chrisbliss18/php-ico creates valid ICO files including multiple embedded resolutions from PNG files and other file formats using only PHP and the GD library.
经过一些谷歌搜索和简单的实验后,看起来 .ico 文件基本上是带有另一个文件扩展名的 BMP。我相信 ICO 格式在一个文件中支持更多分辨率,但 BMP 似乎构成了一个最小的 ICO 文件。您应该能够使用 gd 或 ImageMagick 轻松生成 BMP 文件。
After some googling and light experimentation, it appears that an .ico file is basically a BMP with another file extension. I believe the ICO format supports more resolutions in one file, but a BMP seems to constitute a minimal ICO file. You should be able to generate BMP files easily with gd or ImageMagick.
这似乎表明Imagick 可以做到这一点。
否则,您可以使用外部工具在服务器上进行转换并提供 .ico 文件。实现这一目标的工具已经在 Stack Overflow 之前中进行了分析(好吧,做相反的转换,但我敢打赌大多数软件都可以满足您的需要)。
This seems to suggest Imagick can do this.
Otherwise, you could do the conversion on the server using an external tool and server the .ico file. Tools to achieve this have been analyzed in Stack Overflow before (well, doing the opposite transformation, but I bet most of that software can do what you need).
通过 php 内置库,没有简单的方法可以直接执行此操作。要写入 ico 文件,您需要手动写入各个位和字节以适应文件格式。最简单的方法是使用第三方库。
phpthumb 是一个很好的工具。
http://phpthumb.sourceforge.net/
There is no easy way to do this directly though php built in libraries. To write an ico file, you will need to write individual bits and bytes by hand to suit the file format. The easiest way would be to use a third party library.
phpthumb is a good tool for this.
http://phpthumb.sourceforge.net/
我会尝试一下 floIcon: http://tech.flobi.com/test/floIcon/
I would give floIcon a try: http://tech.flobi.com/test/floIcon/
对于我的 WP 插件: http://wordpress.org/extend/plugins/wp-favicons/< /a> 我正在使用这个 ico 库: http://www.tom-reitz.com/2009/02/17/php-ico-to-png-conversion/comment-page-1/#comment-14883 这是代码: http:// plugins.trac.wordpress.org/browser/wp-favicons/trunk/plugins/filters/convert_to_png.php
它适用于几乎所有图标,但有些像这里找到的图标: http://www.slatch.com/ 给我:注意:未初始化的字符串偏移量:第 296 行上的 64 等。
所以...如果你找到了一个比我更好的 .ico php 库,我可以用另一个库替换它:)
For my WP plugin: http://wordpress.org/extend/plugins/wp-favicons/ I am using this ico lib: http://www.tom-reitz.com/2009/02/17/php-ico-to-png-conversion/comment-page-1/#comment-14883 here is the code : http://plugins.trac.wordpress.org/browser/wp-favicons/trunk/plugins/filters/convert_to_png.php
It works with almost all icons but some like an icon found here: http://www.slatch.com/ give me : Notice: Uninitialized string offset: 64 etc... on line 296.
So... if you have found a better .ico php lib than I can replace that one with another one :)