Fix favicon: support JPG/WebP/GIF, add logging, fix path resolution
Some checks failed
Repo Health / Access control (push) Successful in 1s
Auto-Update SHA Hash / Update SHA-256 Hash in updates.xml (release) Failing after 5s
Repo Health / Scripts governance (push) Successful in 3s
Repo Health / Release configuration (push) Failing after 3s
Repo Health / Repository health (push) Failing after 3s
Some checks failed
Repo Health / Access control (push) Successful in 1s
Auto-Update SHA Hash / Update SHA-256 Hash in updates.xml (release) Failing after 5s
Repo Health / Scripts governance (push) Successful in 3s
Repo Health / Release configuration (push) Failing after 3s
Repo Health / Repository health (push) Failing after 3s
- Support all common image formats (PNG, JPEG, GIF, WebP, BMP) not just PNG — uses getimagesize() to detect type - Add Log::add() warnings when generation fails (GD missing, file not found, unsupported format) - Fix source path: try both direct path and images/ prefix to handle Joomla media field variations Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Log\Log;
|
||||
|
||||
class MokoFaviconHelper
|
||||
{
|
||||
/**
|
||||
@@ -39,7 +41,13 @@ class MokoFaviconHelper
|
||||
*/
|
||||
public static function generate(string $sourcePath, string $outputDir): bool
|
||||
{
|
||||
if (!is_file($sourcePath) || !extension_loaded('gd')) {
|
||||
if (!extension_loaded('gd')) {
|
||||
Log::add('Favicon: GD extension not loaded', Log::WARNING, 'mokocassiopeia');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_file($sourcePath)) {
|
||||
Log::add('Favicon: source file not found: ' . $sourcePath, Log::WARNING, 'mokocassiopeia');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -55,8 +63,24 @@ class MokoFaviconHelper
|
||||
return true;
|
||||
}
|
||||
|
||||
$source = imagecreatefrompng($sourcePath);
|
||||
// Detect image type and load accordingly
|
||||
$imageInfo = @getimagesize($sourcePath);
|
||||
if ($imageInfo === false) {
|
||||
Log::add('Favicon: cannot read image info from ' . $sourcePath, Log::WARNING, 'mokocassiopeia');
|
||||
return false;
|
||||
}
|
||||
|
||||
$source = match ($imageInfo[2]) {
|
||||
IMAGETYPE_PNG => @imagecreatefrompng($sourcePath),
|
||||
IMAGETYPE_JPEG => @imagecreatefromjpeg($sourcePath),
|
||||
IMAGETYPE_GIF => @imagecreatefromgif($sourcePath),
|
||||
IMAGETYPE_WEBP => function_exists('imagecreatefromwebp') ? @imagecreatefromwebp($sourcePath) : false,
|
||||
IMAGETYPE_BMP => function_exists('imagecreatefrombmp') ? @imagecreatefrombmp($sourcePath) : false,
|
||||
default => false,
|
||||
};
|
||||
|
||||
if (!$source) {
|
||||
Log::add('Favicon: unsupported image type (' . ($imageInfo['mime'] ?? 'unknown') . ') at ' . $sourcePath, Log::WARNING, 'mokocassiopeia');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user