开发者

Issue converting ICO to PNG using PHP

Context: Favicons

I am writing a WordPress plugin to download favicons and also convert them to png:

Issue converting ICO to PNG using PHP

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:

Issue converting ICO to PNG using PHP

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 开发者_StackOverflowread .ico (all sorts of) via get_as_string instead of get_from_file which is better?

PS

I already read:

  • Issue converting ICO to PNG using PHP

    How to convert .ICO to .PNG? (tools)
  • Issue converting ICO to PNG using PHP

    Convert png file to ico with PHP
  • Issue converting ICO to PNG using PHP

    Favicon to PNG in PHP


The example icon you posted is monochrome (1 BPP). Its possible the library does not support such a low color depth.


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

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.


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?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜