2023-05-28 17:49:13 +00:00
|
|
|
<?php
|
2023-06-17 02:16:55 +00:00
|
|
|
require __DIR__ . '/../sig.php';
|
|
|
|
|
|
|
|
if(is_file(NP_INFO)) {
|
2023-06-17 02:19:22 +00:00
|
|
|
$nowPlaying = true;
|
2023-06-17 02:16:55 +00:00
|
|
|
$npInfo = unserialize(file_get_contents(NP_INFO));
|
|
|
|
} else $nowPlaying = false;
|
2023-05-28 17:49:13 +00:00
|
|
|
|
|
|
|
$reqMethod = $_SERVER['REQUEST_METHOD'];
|
|
|
|
$reqPath = '/' . trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
|
|
|
|
|
|
|
|
if($reqMethod !== 'HEAD' && $reqMethod !== 'GET') {
|
|
|
|
http_response_code(405);
|
|
|
|
header('Allow: GET, HEAD');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($reqPath === '/np' || $reqPath === '/redir.php') {
|
|
|
|
http_response_code(302);
|
2023-06-17 02:16:55 +00:00
|
|
|
header('Location: ' . ($nowPlaying ? $npInfo->url : 'https://flash.moe'));
|
2023-05-28 17:49:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($reqPath === '/source' || $reqPath === '/sig-src.php') {
|
|
|
|
http_response_code(301);
|
|
|
|
header('Location: https://git.flash.moe/flash/signature');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(in_array($reqPath, [
|
|
|
|
'/', '/index.php', '/signature.php', '/signature.png',
|
|
|
|
'/album.png', '/album1.png', '/album2.png',
|
|
|
|
'/body.png', '/body1.png', '/body2.png',
|
|
|
|
])) {
|
2023-06-17 02:16:55 +00:00
|
|
|
$ip_000 = new ImagickPixel('#000');
|
|
|
|
$ip_444 = new ImagickPixel('#444');
|
|
|
|
$ip_fff = new ImagickPixel('#fff');
|
|
|
|
|
|
|
|
$imagick = new Imagick;
|
|
|
|
$imagick->newImage(SIG_WIDTH, SIG_HEIGHT, $ip_000, 'png');
|
|
|
|
|
|
|
|
$background = new Imagick(BG_PATH . DIRECTORY_SEPARATOR . BG_IMAGE);
|
|
|
|
$imagick->compositeImage($background, Imagick::COMPOSITE_COPY, 0, 0);
|
|
|
|
$background->destroy();
|
|
|
|
|
|
|
|
$footer = new Imagick(SIG_FOOTER);
|
|
|
|
$footerHeight = $footer->getImageHeight() - ($nowPlaying ? 0 : 10);
|
|
|
|
|
|
|
|
$imagick->compositeImage($footer, Imagick::COMPOSITE_MATHEMATICS, 0, SIG_HEIGHT - $footerHeight);
|
|
|
|
$footer->destroy();
|
|
|
|
|
|
|
|
$imagickDraw = new ImagickDraw;
|
|
|
|
$imagickDraw->setFillColor($ip_444);
|
|
|
|
$imagickDraw->setFont(FW_FONT_FAM);
|
|
|
|
$imagickDraw->setFontSize(FW_FONT_SIZE);
|
|
|
|
|
|
|
|
$hasCover = $nowPlaying && is_file(NP_COVER_IMG);
|
|
|
|
|
|
|
|
if($hasCover) {
|
2023-06-21 00:31:15 +00:00
|
|
|
try {
|
|
|
|
$imagickDraw->rectangle(
|
|
|
|
SIG_WIDTH - (NP_COVER_RES + NP_COVER_PAD) - NP_COVER_FRAME,
|
|
|
|
NP_COVER_PAD - NP_COVER_FRAME,
|
|
|
|
SIG_WIDTH - (NP_COVER_RES + NP_COVER_PAD) + NP_COVER_RES,
|
|
|
|
NP_COVER_PAD + NP_COVER_RES,
|
|
|
|
);
|
|
|
|
|
|
|
|
$npCover = new Imagick(NP_COVER_IMG);
|
|
|
|
$npCover->resizeImage(NP_COVER_RES, NP_COVER_RES, Imagick::FILTER_CATROM, 0.9, true);
|
|
|
|
|
|
|
|
$imagick->drawImage($imagickDraw);
|
|
|
|
$imagick->compositeImage($npCover, Imagick::COMPOSITE_COPY, SIG_WIDTH - (NP_COVER_RES + NP_COVER_PAD), NP_COVER_PAD);
|
|
|
|
|
|
|
|
$npCover->destroy();
|
|
|
|
} catch(ImagickException $ex) {
|
|
|
|
$hasCover = false;
|
|
|
|
}
|
2023-06-17 02:16:55 +00:00
|
|
|
}
|
2023-05-28 17:49:13 +00:00
|
|
|
|
2023-06-17 02:16:55 +00:00
|
|
|
$imagickDraw->setFillColor(BG_IMAGE === 'bg4.png' ? $ip_000 : $ip_fff);
|
2023-05-28 17:49:13 +00:00
|
|
|
|
2023-06-17 02:16:55 +00:00
|
|
|
$imagickLogo = new Imagick();
|
|
|
|
$imagickLogo->newImage($imagick->getImageWidth(), $imagick->getImageHeight(), new ImagickPixel('none'), 'png');
|
|
|
|
$imagickLogo->annotateImage(
|
|
|
|
$imagickDraw,
|
|
|
|
SIG_WIDTH - (4.8 * FW_FONT_SIZE) - ($hasCover ? (NP_COVER_RES + NP_COVER_PAD + NP_COVER_FRAME) : 0),
|
|
|
|
SIG_HEIGHT - ($nowPlaying ? 37 : 27),
|
|
|
|
0,
|
|
|
|
FW_TEXT
|
|
|
|
);
|
2023-05-28 17:49:13 +00:00
|
|
|
|
2023-06-17 02:16:55 +00:00
|
|
|
$imagickShadow = clone $imagickLogo;
|
|
|
|
$imagickShadow->shadowImage(.8, 5, 0, 0);
|
|
|
|
$imagickShadow->compositeImage($imagickLogo, Imagick::COMPOSITE_OVER, 4, 2);
|
|
|
|
$imagickLogo->destroy();
|
2023-06-17 01:14:28 +00:00
|
|
|
|
2023-06-17 02:16:55 +00:00
|
|
|
$imagick->compositeImage($imagickShadow, Imagick::COMPOSITE_OVER, -4, -2);
|
|
|
|
$imagickShadow->destroy();
|
2023-06-17 01:14:28 +00:00
|
|
|
|
2023-06-17 02:16:55 +00:00
|
|
|
$imagickDraw->setFillColor($ip_fff);
|
2023-05-28 17:49:13 +00:00
|
|
|
|
2023-06-17 02:16:55 +00:00
|
|
|
if($nowPlaying) {
|
|
|
|
$imagickDraw->setFont(FA_FONT_FAM);
|
|
|
|
$imagickDraw->setFontSize(NP_FONT_SIZE_ICON);
|
|
|
|
$imagick->annotateImage($imagickDraw, 8, SIG_HEIGHT - 9, 0, "\u{f001}");
|
|
|
|
|
|
|
|
$imagickDraw->setFont(NP_FONT_FAM);
|
|
|
|
$imagickDraw->setFontSize(NP_FONT_SIZE);
|
|
|
|
$imagick->annotateImage($imagickDraw, 32, SIG_HEIGHT - 5, 0, $npInfo->title);
|
|
|
|
|
|
|
|
$imagickDraw->setFontSize(NP_FONT_SIZE_SMALL);
|
|
|
|
$imagick->annotateImage($imagickDraw, 32, SIG_HEIGHT - 20, 0, $npInfo->artist);
|
|
|
|
} else {
|
|
|
|
$imagickDraw->setFont(NP_FONT_FAM);
|
|
|
|
$imagickDraw->setFontSize(NP_FONT_SIZE);
|
2023-06-17 02:18:24 +00:00
|
|
|
$imagick->annotateImage($imagickDraw, 10, SIG_HEIGHT - 4, 0, "If it ain't broke, I'll break it");
|
2023-05-28 17:49:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$fileName = pathinfo($reqPath, PATHINFO_FILENAME);
|
|
|
|
|
|
|
|
switch($fileName) {
|
|
|
|
case 'album':
|
|
|
|
$imagick->cropImage(SIG_HEIGHT, SIG_HEIGHT, SIG_WIDTH - SIG_HEIGHT, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'album1':
|
2023-06-17 01:14:28 +00:00
|
|
|
$imagick->cropImage(SIG_HEIGHT, SIG_HEIGHT - $footerHeight, SIG_WIDTH - SIG_HEIGHT, 0);
|
2023-05-28 17:49:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'album2':
|
2023-06-17 01:14:28 +00:00
|
|
|
$imagick->cropImage(SIG_HEIGHT, $footerHeight, SIG_WIDTH - SIG_HEIGHT, SIG_HEIGHT - $footerHeight);
|
2023-05-28 17:49:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'body':
|
|
|
|
$imagick->cropImage(SIG_WIDTH - SIG_HEIGHT, SIG_HEIGHT, 0, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'body1':
|
2023-06-17 01:14:28 +00:00
|
|
|
$imagick->cropImage(SIG_WIDTH - SIG_HEIGHT, SIG_HEIGHT - $footerHeight, 0, 0);
|
2023-05-28 17:49:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'body2':
|
2023-06-17 01:14:28 +00:00
|
|
|
$imagick->cropImage(SIG_WIDTH - SIG_HEIGHT, $footerHeight, 0, SIG_HEIGHT - $footerHeight);
|
2023-05-28 17:49:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$fileName = 'signature';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
header('Content-Type: image/png');
|
|
|
|
header('Cache-Control: max-age=' . SIG_AGE . ', public');
|
|
|
|
header('Content-Disposition: inline; filename="' . $fileName . '.png"');
|
|
|
|
echo $imagick->getImageBlob();
|
|
|
|
|
|
|
|
$imagick->destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
http_response_code(404);
|
|
|
|
echo '404';
|