Favicon for PNG to PHP

I need a PHP script to convert icons to PNG, preserving their original sizes.

I know that Google has a secret icon converter - http://www.google.com/s2/favicons?domain=http://facebook.com/ , but this converts the icons to 16x16, even if they were originally larger. So basically I need it, minus the diminishing effect.

I also saw this - http://www.controlstyle.com/articles/programming/text/php-favicon/ , but I could not get it to work after several hours of talking with him.

Basically, I am trying to automatically grab the icon for the link, which will be as large as possible - automatically 48x48 png based on the URL will be the ideal scenario, but I don’t know any humanly possible way to do this that no websites contain the 48x48 icon in a public place.

Does anyone know about a script / service or have a suggestion? Thanks!

+7
source share
6 answers

So, I ended up using the FloIcon class, which could convert BMP to ICO. I should note that it is always important to check the file type of the icon and not assume that .ico means bmp, because some sites (like Facebook) were actually PNG).

@ goker.cebeci Your service looks amazing! The main thing is that I need my icons to be the maximum size when possible, so I just wrote my own script.

+4
source

Here is the function to convert from bmp (ico) to png http://us3.php.net/manual/en/function.imagecreate.php#53879

  • Upload ico to your server (file_get_contents or other methods), usually it is favicon.ico on the base url or clear the html code for the element <link rel="shortcut icon" href="ico_url_here" type="image/x-icon" /> and remove href
  • use the function from the above link to convert to png
  • use the gd functions to open and resize

$ image = imagecreatefrompng ($ filename);
$ resized_image = imagecreatetruecolor ($ NewWidth, $ NewHeight);
imagecopyresampled ($ resized_image, $ image, 0, 0, 0, 0, $ NewWidth, $ NewHeight, $ OriginalWidth, $ OriginalHeight);

4 Save the file (imagepng or similar)

+3
source

I used Imagemagick in my favicon project in PNG .

 convert "favicon.ico" -thumbnail 16x16 -alpha on -background none -flatten "favicon.png" 

The fracists of some websites have a scene, and their sizes are larger than 16x16 pixels, for example: http://blogger.com/favicon.ico

http://www.google.com/s2/favicons?domain=http://facebook.com/ does not work correctly. So, I developed a web service for this.

If you want to try my web service, you can go this way http://geticon.org/of/http://facebook.com/ or this way http://geticon.org/of/facebook.com

+2
source

The code http://www.controlstyle.com/articles/programming/text/php-favicon/ has a small error:

You need to change $entry['swBitCount'] to $entry['wBitCount'] . When I did this, changing all work permissions

+1
source

imagecopyresized - documents also contain an example

The above requires compilation with the --with-gd option

I assume you did not know about the imagick extension as well

etc: all possible extensions / image processing functions

0
source

Im using here: http://plugins.trac.wordpress.org/browser/wp-favicons/trunk/plugins/filters/convert_to_png.php a lib from here: http://www.tom-reitz.com/2009/ 02/09 / ico-images-in-facebook-profile-boxes /

(I did not want to save ico to disk first)

The only problem with lib is that it sometimes fails on XOR, for example. on this icon: http://www.slatch.com/

So, this is what I need to fix, but in addition, it did a great job with thousands of icons.

0
source

All Articles