diff --git a/README.md b/README.md index 9cc7cb2..eb83c12 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,4 @@ Backgrounds images: - bg3.png - イッポンシメジ [pixiv](https://www.pixiv.net/en/artworks/32809110) - bg4.png - [Minitokyo](http://gallery.minitokyo.net/view/630668) - bg5.png - K3rd [Twitter](https://twitter.com/ryousangataK/status/1209809508156837891) [Danbooru](https://danbooru.donmai.us/posts/4379783) + - bg6.png - karory [Danbooru](https://danbooru.donmai.us/posts/900741) diff --git a/public/bg/bg6.png b/public/bg/bg6.png new file mode 100644 index 0000000..3b8dc46 Binary files /dev/null and b/public/bg/bg6.png differ diff --git a/public/index.php b/public/index.php index d9d7339..b67276b 100644 --- a/public/index.php +++ b/public/index.php @@ -1,22 +1,29 @@ 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) { + if(!SIG_DEBUG && 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_444 = new ImagickPixel('#444'); $ip_fff = new ImagickPixel('#fff'); $npRaw = file_get_contents(NP_URL); @@ -94,29 +94,47 @@ if(in_array($reqPath, [ $background->destroy(); $footer = new Imagick(SIG_FOOTER); - $imagick->compositeImage($footer, Imagick::COMPOSITE_MATHEMATICS, 0, SIG_HEIGHT - $footer->getImageHeight()); + $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); 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); + $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, + ); + $imagick->drawImage($imagickDraw); + + $npCover = new Imagick(NP_COVER); + $npCover->resizeImage(NP_COVER_RES, NP_COVER_RES, Imagick::FILTER_CATROM, 0.9, true); + $imagick->compositeImage($npCover, Imagick::COMPOSITE_COPY, SIG_WIDTH - (NP_COVER_RES + NP_COVER_PAD), NP_COVER_PAD); $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); + $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 + ); $imagickShadow = clone $imagickLogo; - $imagickShadow->shadowImage(80, 5, 0, 0); + $imagickShadow->shadowImage(.8, 5, 0, 0); $imagickShadow->compositeImage($imagickLogo, Imagick::COMPOSITE_OVER, 4, 2); $imagickLogo->destroy(); @@ -124,15 +142,22 @@ if(in_array($reqPath, [ $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}"); + $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, $np[0]->name ?? ''); + + $imagickDraw->setFontSize(NP_FONT_SIZE_SMALL); + $imagick->annotateImage($imagickDraw, 32, SIG_HEIGHT - 20, 0, $np[0]->artist->name ?? ''); } else { - $imagick->annotateImage($imagickDraw, 10, 91, 0, "If it ain't broke, I'll break it"); + $imagickDraw->setFont(NP_FONT_FAM); + $imagickDraw->setFontSize(NP_FONT_SIZE); + $imagick->annotateImage($imagickDraw, 10, SIG_HEIGHT - 5, 0, "If it ain't broke, I'll break it"); } file_put_contents(SIG_STATIC, $imagick->getImageBlob()); @@ -146,11 +171,11 @@ if(in_array($reqPath, [ break; case 'album1': - $imagick->cropImage(SIG_HEIGHT, SIG_HEIGHT - 33, SIG_WIDTH - SIG_HEIGHT, 0); + $imagick->cropImage(SIG_HEIGHT, SIG_HEIGHT - $footerHeight, SIG_WIDTH - SIG_HEIGHT, 0); break; case 'album2': - $imagick->cropImage(SIG_HEIGHT, 33, SIG_WIDTH - SIG_HEIGHT, SIG_HEIGHT - 33); + $imagick->cropImage(SIG_HEIGHT, $footerHeight, SIG_WIDTH - SIG_HEIGHT, SIG_HEIGHT - $footerHeight); break; case 'body': @@ -158,11 +183,11 @@ if(in_array($reqPath, [ break; case 'body1': - $imagick->cropImage(SIG_WIDTH - SIG_HEIGHT, SIG_HEIGHT - 33, 0, 0); + $imagick->cropImage(SIG_WIDTH - SIG_HEIGHT, SIG_HEIGHT - $footerHeight, 0, 0); break; case 'body2': - $imagick->cropImage(SIG_WIDTH - SIG_HEIGHT, 33, 0, SIG_HEIGHT - 33); + $imagick->cropImage(SIG_WIDTH - SIG_HEIGHT, $footerHeight, 0, SIG_HEIGHT - $footerHeight); break; default: