Feed

favicon2png

admin on Feb 19th 2008

Here is a script to download the favicon.ico files from a website and save it as a png file.

You must have imagemagick installed on your server to convert the ico file to png.

 
<!--- html code ---->
<form action="?" method="post">
<input id="site" name="site" type="text"
value="<?php echo $_POST['site']; ?/>" />
<input type="submit" />
</form>
 
< ?php
//--- favicon2png by Alireza Balouch @ swape.net 2008
 
if($_POST['site'] != ''){
 
//finding the hostname
$host = parse_url($_POST['site']);
$host = $host['host'];
$host = explode('.' , $host);
$host = $host[count($host) -2];
$filename = 'img/' . $host . '.png';
 
if (!is_file($filename)){
// getting the favicon
$handle = fopen( $_POST['site'] . '/favicon.ico', "rb");
$contents = stream_get_contents($handle);
fclose($handle);
 
file_put_contents('fav.ico' , $contents );
// converting to png
$StrExec = '/usr/local/bin/convert fav.ico -resize 24x24\> ' . $filename ;
$ret = exec($StrExec);
}
echo '<img src="' . $filename . '" />' . $_POST['site'];
}
?>

Filed in Scripts | No responses yet

Trackback URI |

Leave a Reply

You must be logged in to post a comment.