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)
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.
An example is this icon: click here to see (navigates to slatch.com)
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?
I already read:
(PHP 4, PHP 5, PHP 7, PHP 8) imagepng— Output a PNG image to either the browser or a file Description imagepng( GdImage$image, resource|string|null$file= null, int$quality= -1, int$filters= -1 ): bool
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.
The base64_encode () function is an inbuilt function in PHP which is used to convert any data to base64 encoding. In order to convert an image into base64 encoding firstly need to get the contents of file. This can be done with the help of file_get_contents () function of PHP.
When changeing the PHP version from 4 to 5 I found out, that PHP5 handles imagepng() more restrictive than in PHP4. I'd used imagepng($image,'',90); to reduce the image quality whithout saving the image as a file.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With