Support png avatars
[gamestick-pjgsapi.git] / src / Profile.php
index ca204ac7909fb45fb92192754b322c4643df4803..e120546750d44e2753fe1c73a7d530e5532faa2d 100644 (file)
@@ -4,6 +4,8 @@
  */
 class Profile
 {
+    protected string $avatarDir;
+
     public int $id;
     public string $hwId;
     public string $sessionId;
@@ -16,6 +18,11 @@ class Profile
 
     public string $created_at;
 
+    public function __construct()
+    {
+        $this->avatarDir = dirname(__FILE__) . '/../www/resources/avatars/';
+    }
+
     public function complete(): bool
     {
         return $this->gamerTag !== null;
@@ -26,8 +33,15 @@ class Profile
         if (strpos($this->avatar, '://')) {
             return $this->avatar;
         }
+
+        if (file_exists($this->avatarDir . $this->avatar . '.large.jpg')) {
+            $ext = 'jpg';
+        } else {
+            $ext = 'png';
+        }
+
         return 'http://l2.gamestickservices.net/resources/avatars/'
-            . $this->avatar . '.large.jpg';
+            . $this->avatar . '.large.' . $ext;
     }
 
     public function getAvatarSmallUrl(): string
@@ -35,7 +49,14 @@ class Profile
         if (strpos($this->avatar, '://')) {
             return $this->avatar;
         }
+
+        if (file_exists($this->avatarDir . $this->avatar . '.small.jpg')) {
+            $ext = 'jpg';
+        } else {
+            $ext = 'png';
+        }
+
         return 'http://l2.gamestickservices.net/resources/avatars/'
-            . $this->avatar . '.small.jpg';
+            . $this->avatar . '.small.' . $ext;
     }
 }