34
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Genera los íconos PWA en public/icons/ usando public/logo.png como fuente.
|
||||
* Ejecutar desde la raíz: php scripts/generate-pwa-icons.php
|
||||
*/
|
||||
|
||||
$outputDir = __DIR__ . '/../public/icons';
|
||||
$sourcePng = __DIR__ . '/../public/favicon_source.png';
|
||||
$sourceFav = __DIR__ . '/../public/favicon.ico';
|
||||
$sourceLogo = __DIR__ . '/../public/logo.png';
|
||||
|
||||
$sizes = [72, 96, 128, 144, 152, 192, 384, 512];
|
||||
|
||||
if (!is_dir($outputDir)) {
|
||||
mkdir($outputDir, 0755, true);
|
||||
echo "✅ Directorio creado: {$outputDir}\n";
|
||||
}
|
||||
|
||||
// Intentar cargar la fuente (preferencia favicon_source.png extraído)
|
||||
$srcImage = null;
|
||||
if (file_exists($sourcePng)) {
|
||||
$srcImage = @imagecreatefrompng($sourcePng);
|
||||
if ($srcImage) {
|
||||
echo "✅ Fuente cargada desde Favicon Extraído: {$sourcePng}\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (!$srcImage && file_exists($sourceFav)) {
|
||||
$data = file_get_contents($sourceFav);
|
||||
$srcImage = @imagecreatefromstring($data);
|
||||
if ($srcImage) {
|
||||
echo "✅ Fuente cargada desde Favicon: {$sourceFav}\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (!$srcImage && file_exists($sourceLogo)) {
|
||||
$srcImage = @imagecreatefrompng($sourceLogo);
|
||||
if ($srcImage) {
|
||||
echo "✅ Fuente cargada desde Logo: {$sourceLogo}\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($srcImage) {
|
||||
imagealphablending($srcImage, true);
|
||||
imagesavealpha($srcImage, true);
|
||||
} else {
|
||||
echo "⚠️ No se pudo cargar ninguna fuente (Favicon o Logo).\n";
|
||||
}
|
||||
|
||||
|
||||
foreach ($sizes as $size) {
|
||||
$img = imagecreatetruecolor($size, $size);
|
||||
|
||||
// Configurar transparencia total
|
||||
imagealphablending($img, false);
|
||||
$transparent = imagecolorallocatealpha($img, 0, 0, 0, 127);
|
||||
imagefill($img, 0, 0, $transparent);
|
||||
imagesavealpha($img, true);
|
||||
imagealphablending($img, true);
|
||||
|
||||
// Si tenemos imagen fuente, superponerla centrada (90% del tamaño para aprovechar mejor el espacio si es transparente)
|
||||
if ($srcImage) {
|
||||
$srcW = imagesx($srcImage);
|
||||
$srcH = imagesy($srcImage);
|
||||
$dstSize = (int)($size * 0.90);
|
||||
$dstX = (int)(($size - $dstSize) / 2);
|
||||
$dstY = (int)(($size - $dstSize) / 2);
|
||||
imagecopyresampled($img, $srcImage, $dstX, $dstY, 0, 0, $dstSize, $dstSize, $srcW, $srcH);
|
||||
} else {
|
||||
// Sin logo: fallback a fondo rojo pero con texto blanco
|
||||
$bgRed = imagecolorallocate($img, 176, 0, 0);
|
||||
imagefill($img, 0, 0, $bgRed);
|
||||
$white = imagecolorallocate($img, 255, 255, 255);
|
||||
$fontSize = max(2, (int)($size / 5));
|
||||
$text = 'APB';
|
||||
$tx = (int)($size / 2 - strlen($text) * 3 * min($fontSize / 5, 3));
|
||||
$ty = (int)($size / 2 - $fontSize);
|
||||
imagestring($img, min(5, $fontSize), max(0, $tx), max(0, $ty), $text, $white);
|
||||
}
|
||||
|
||||
$output = "{$outputDir}/icon-{$size}.png";
|
||||
imagepng($img, $output);
|
||||
imagedestroy($img);
|
||||
|
||||
echo "✅ Generado: icon-{$size}.png\n";
|
||||
}
|
||||
|
||||
if ($srcImage) imagedestroy($srcImage);
|
||||
|
||||
echo "\n✅ Todos los íconos PWA generados en: {$outputDir}\n";
|
||||
echo " Podés reemplazarlos por versiones de mayor calidad en cualquier momento.\n";
|
||||
Reference in New Issue
Block a user