If the favicon isn't located at /favicon.ico I guess you have to parse the HTML.
For the filetype detection, you can use this extension, which detects the filetype by using magic bytes.
You can convert to PNG by using the GD library, an example can be found here.