Browse Source

Resize images

Sunny 2 years ago
parent
commit
cffab0e0d5
4 changed files with 17 additions and 2 deletions
  1. 3 0
      pages/artist.php
  2. 3 1
      pages/release.php
  3. 1 1
      pages/search.php
  4. 10 0
      utilities/link.php

+ 3 - 0
pages/artist.php

@@ -30,6 +30,7 @@
 
     $image = $release->find("img");
     $image = $image->hasAttr("data-original") ? $image->attr("data-original") : $image->attr("src");
+    $image = resize_link($image, 3);
     $image = convert_link($image);
 
     $link = $release->find("a")->attr("href");
@@ -45,6 +46,8 @@
   echo "</div>";
 
   $image = $document->find(".bio-pic a")->attr("href");
+  $image = resize_link($image, 4);
+
   $description = $document->find("meta[property=\"og:description\"]")->attr("content");
   $links = $document->find("#band-links li a");
 

+ 3 - 1
pages/release.php

@@ -29,7 +29,7 @@
 
     echo "<div class=\"subpage\">";
 
-    $image = "https://f4.bcbits.com/img/" . $json->art_id . "_10.jpg";
+    $image = "https://f4.bcbits.com/img/" . $json->art_id . "_4.jpg";
 
     $about = $json->current->about;
     $description = $additional->inAlbum->albumRelease[0]->additionalProperty;
@@ -88,6 +88,8 @@
     echo "</div>";
 
     $image = $document->find(".bio-pic a")->attr("href");
+    $image = resize_link($image, 4);
+
     if (isset($additional->publisher->description))
       $text = $additional->publisher->description;
     else

+ 1 - 1
pages/search.php

@@ -41,7 +41,7 @@
         break;
     };
 
-    echo_item($link, convert_link($result->img), htmlspecialchars($result->name), $text ?? null);
+    echo_item($link, convert_link(resize_link($result->img, 3)), htmlspecialchars($result->name), $text ?? null);
   };
 
   if (empty($results))

+ 10 - 0
utilities/link.php

@@ -62,4 +62,14 @@
     else
       return $link;
   };
+
+  function resize_link($link, $size) {
+    $host = parse_url($link, PHP_URL_HOST);
+    if ($host !== "f4.bcbits.com") return $link;
+
+    $file = pathinfo($link)["filename"];
+    $ext = pathinfo($link)["extension"];
+
+    return "https://" . $host . "/img/" . explode("_", $file)[0] . "_" . $size . "." . $ext;
+  };
 ?>