Convert png file to ico with PHP

2020-02-05 04:31发布

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 !!!

标签: php png gd icons
6条回答
Bombasti
2楼-- · 2020-02-05 04:53

I would give floIcon a try: http://tech.flobi.com/test/floIcon/

查看更多
小情绪 Triste *
3楼-- · 2020-02-05 04:54

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.

查看更多
爷、活的狠高调
4楼-- · 2020-02-05 04:54

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/

查看更多
淡お忘
5楼-- · 2020-02-05 05:14

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 :)

查看更多
淡お忘
6楼-- · 2020-02-05 05:15

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.

查看更多
Viruses.
7楼-- · 2020-02-05 05:18

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).

查看更多
登录 后发表回答