开发者

Convert png file to ico with PHP

开发者 https://www.devze.com 2022-12-26 09:47 出处:网络
I would li开发者_如何学Pythonke to create a PHP script that convert a png file to an ico file. Is it possible to do it just with PHP ? How ?

I would li开发者_如何学Pythonke 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 !!!


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.


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.


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


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/


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消