diff --git a/public/bg/bg1.png b/public/bg/bg1.png new file mode 100644 index 0000000..0fa2562 Binary files /dev/null and b/public/bg/bg1.png differ diff --git a/public/bg/bg2.png b/public/bg/bg2.png new file mode 100644 index 0000000..e88de46 Binary files /dev/null and b/public/bg/bg2.png differ diff --git a/public/bg/bg3.png b/public/bg/bg3.png new file mode 100644 index 0000000..4096642 Binary files /dev/null and b/public/bg/bg3.png differ diff --git a/public/bg/bg4.png b/public/bg/bg4.png new file mode 100644 index 0000000..23a8ce2 Binary files /dev/null and b/public/bg/bg4.png differ diff --git a/public/bg/bg5.png b/public/bg/bg5.png new file mode 100644 index 0000000..7573ebc Binary files /dev/null and b/public/bg/bg5.png differ diff --git a/public/ex/Electrolize-Regular.ttf b/public/ex/Electrolize-Regular.ttf new file mode 100644 index 0000000..ace9ba2 Binary files /dev/null and b/public/ex/Electrolize-Regular.ttf differ diff --git a/public/ex/NotoSansJP-Regular.otf b/public/ex/NotoSansJP-Regular.otf new file mode 100644 index 0000000..de78e6d Binary files /dev/null and b/public/ex/NotoSansJP-Regular.otf differ diff --git a/public/ex/fa-solid-900.ttf b/public/ex/fa-solid-900.ttf new file mode 100644 index 0000000..7ece328 Binary files /dev/null and b/public/ex/fa-solid-900.ttf differ diff --git a/public/ex/footer.png b/public/ex/footer.png new file mode 100644 index 0000000..822faed Binary files /dev/null and b/public/ex/footer.png differ diff --git a/public/ex/no-cover.png b/public/ex/no-cover.png new file mode 100644 index 0000000..801761a Binary files /dev/null and b/public/ex/no-cover.png differ diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..d9d7339 --- /dev/null +++ b/public/index.php @@ -0,0 +1,183 @@ +nowplaying) && !empty($np[0]->url)) + header('Location: ' . $np[0]->url); + else + header('Location: https://flash.moe'); + 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', +])) { + $currentDate = (int)ltrim(date('md'), '0'); + + if($currentDate > 1205 && $currentDate < 1227) { + define('BG_IMAGE', 'bg5.png'); + } else { + define('BG_IMAGE', 'bg4.png'); + } + + if(!isset($_GET['_force']) && is_file(SIG_STATIC) && time() - filemtime(SIG_STATIC) < SIG_AGE) { + header('X-Sig-State: cache'); + $imagick = new Imagick(SIG_STATIC); + } else { + header('X-Sig-State: fresh'); + $ip_000 = new ImagickPixel('#000'); + $ip_fff = new ImagickPixel('#fff'); + + $npRaw = file_get_contents(NP_URL); + $np = json_decode($npRaw); + + if(is_array($np)) { + file_put_contents(NP_FILE, $npRaw); + + if(empty($np[0]->images->large) || $np[0]->images->large === NP_COVER_URL_DEFAULT) { + unlink(NP_COVER); + file_put_contents(NP_COVER_URL, ''); + } elseif(!empty($np[0]->images->large) && $np[0]->images->large !== file_get_contents(NP_COVER_URL)) { + unlink(NP_COVER); + file_put_contents(NP_COVER_URL, $np[0]->images->large); + file_put_contents(NP_COVER, file_get_contents($np[0]->images->large)); + } + } + + if(empty($np)) + $np = json_decode(file_get_contents(NP_FILE)); + + $nowPlaying = is_array($np) && !empty($np[0]->nowplaying); + + $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); + $imagick->compositeImage($footer, Imagick::COMPOSITE_MATHEMATICS, 0, SIG_HEIGHT - $footer->getImageHeight()); + $footer->destroy(); + + $hasCover = $nowPlaying && is_file(NP_COVER); + + if($hasCover) { + $npCover = new Imagick(/*is_file(NP_COVER) ?*/ NP_COVER /*: NP_COVER_DEFAULT*/); + $npCover->resizeImage(80, 80, Imagick::FILTER_CATROM, 0.9, true); + $imagick->compositeImage($npCover, Imagick::COMPOSITE_COPY, SIG_WIDTH - 90, 10); + $npCover->destroy(); + } + + $imagickDraw = new ImagickDraw; + $imagickDraw->setFillColor(BG_IMAGE === 'bg4.png' ? $ip_000 : $ip_fff); + $imagickDraw->setFont(FW_FONT_FAM); + $imagickDraw->setFontSize(FW_FONT_SIZE); + + $imagickLogo = new Imagick(); + $imagickLogo->newImage($imagick->getImageWidth(), $imagick->getImageHeight(), new ImagickPixel('none'), 'png'); + $imagickLogo->annotateImage($imagickDraw, $hasCover ? 367 : 457, 60, 0, FW_TEXT); + + $imagickShadow = clone $imagickLogo; + $imagickShadow->shadowImage(80, 5, 0, 0); + $imagickShadow->compositeImage($imagickLogo, Imagick::COMPOSITE_OVER, 4, 2); + $imagickLogo->destroy(); + + $imagick->compositeImage($imagickShadow, Imagick::COMPOSITE_OVER, -4, -2); + $imagickShadow->destroy(); + + $imagickDraw->setFillColor($ip_fff); + $imagickDraw->setFont(NP_FONT_FAM); + $imagickDraw->setFontSize(NP_FONT_SIZE); + + if($nowPlaying) { + $imagick->annotateImage($imagickDraw, 40, 91, 0, sprintf('%s - %s', $np[0]->artist->name ?? '', $np[0]->name ?? '')); + $imagickDraw->setFont(FA_FONT_FAM); + $imagick->annotateImage($imagickDraw, 10, 91, 0, "\u{f001}"); + } else { + $imagick->annotateImage($imagickDraw, 10, 91, 0, "If it ain't broke, I'll break it"); + } + + file_put_contents(SIG_STATIC, $imagick->getImageBlob()); + } + + $fileName = pathinfo($reqPath, PATHINFO_FILENAME); + + switch($fileName) { + case 'album': + $imagick->cropImage(SIG_HEIGHT, SIG_HEIGHT, SIG_WIDTH - SIG_HEIGHT, 0); + break; + + case 'album1': + $imagick->cropImage(SIG_HEIGHT, SIG_HEIGHT - 33, SIG_WIDTH - SIG_HEIGHT, 0); + break; + + case 'album2': + $imagick->cropImage(SIG_HEIGHT, 33, SIG_WIDTH - SIG_HEIGHT, SIG_HEIGHT - 33); + break; + + case 'body': + $imagick->cropImage(SIG_WIDTH - SIG_HEIGHT, SIG_HEIGHT, 0, 0); + break; + + case 'body1': + $imagick->cropImage(SIG_WIDTH - SIG_HEIGHT, SIG_HEIGHT - 33, 0, 0); + break; + + case 'body2': + $imagick->cropImage(SIG_WIDTH - SIG_HEIGHT, 33, 0, SIG_HEIGHT - 33); + 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';