gaffling / PHP-Grab-Favicon

🖼 Saves the favicon of the given URL and returns the image path.
http://suchmaschine.biz
MIT License
26 stars 6 forks source link

Checking Extensions #4

Closed LeeThompson closed 1 year ago

LeeThompson commented 1 year ago

This won't work for the file exist check but this will apply the correct extension (as long as exif_imagetype knows it) when saving icons locally.

This has "ico" as the default extension although in reality the one it's most likely to be if it's none of the others is SVG.

      // Write Favicon local
      $iconType = "ico";
      if (exif_imagetype($favicon) == IMAGETYPE_GIF) { $iconType = "gif"; }
      if (exif_imagetype($favicon) == IMAGETYPE_JPEG) { $iconType = "jpg"; }
      if (exif_imagetype($favicon) == IMAGETYPE_PNG) { $iconType = "png"; }
      if (exif_imagetype($favicon) == IMAGETYPE_ICO) { $iconType = "ico"; }
      if (exif_imagetype($favicon) == IMAGETYPE_WEBP) { $iconType = "webp"; }
      if (exif_imagetype($favicon) == IMAGETYPE_BMP) { $iconType = "bmp"; }

      $filePath = preg_replace('#\/\/#', '/', $directory.'/'.$domain.'.' . $iconType);

The file exists check is going to have to check all the common extensions.

gaffling commented 1 year ago

Nice, please make a Pull Request and get all the fame ;-)

LeeThompson commented 1 year ago

Nice, please make a Pull Request and get all the fame ;-)

I'll give it a try, haven't done one before; I'll clean up the code a bit first too.

LeeThompson commented 1 year ago

Submitted as a PR NOTE: Needs testing.

Resubmitted the PR, additional stuff.