]> littlesong.place Git - littlesongplace.git/commitdiff
Use jpeg for profile pictures
authorChris Fulljames <christianfulljames@gmail.com>
Sun, 9 Feb 2025 19:31:53 +0000 (14:31 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Sun, 9 Feb 2025 19:31:53 +0000 (14:31 -0500)
main.py
test/test_offline.py
todo.txt

diff --git a/main.py b/main.py
index fbd61fc0f9c5dcb4cabeac88fc89fc305ee2f4c2..d777b480209c7fa1c17999c80de123a6411839cf 100644 (file)
--- a/main.py
+++ b/main.py
@@ -183,10 +183,14 @@ def edit_profile():
     get_db().commit()
 
     if request.files["pfp"]:
-        pfp_path = get_user_images_path(session["userid"]) / "pfp.png"
+        pfp_path = get_user_images_path(session["userid"]) / "pfp.jpg"
 
         try:
             with Image.open(request.files["pfp"]) as im:
+                # Drop alpha channel
+                if im.mode in ("RGBA", "P"):
+                    im = im.convert("RGB")
+
                 target_size = 256  # Square (same width/height)
                 # Resize
                 if im.width >= im.height:
@@ -218,7 +222,7 @@ def edit_profile():
 
 @app.get("/pfp/<int:userid>")
 def pfp(userid):
-    return send_from_directory(DATA_DIR / "images" / str(userid), "pfp.png")
+    return send_from_directory(DATA_DIR / "images" / str(userid), "pfp.jpg")
 
 @app.get("/edit-song")
 def edit_song():
index 34fd7d8412af6996423e34f4bc191ebe16ce93ff..539f1240619849d442ef54b159cec1116ead5ea8 100644 (file)
@@ -217,7 +217,7 @@ def test_get_pfp(client):
 
     response = client.get("/pfp/1")
     assert response.status_code == 200
-    assert response.mimetype == "image/png"
+    assert response.mimetype == "image/jpeg"
     # Can't check image file, since site has modified it
 
 def test_get_pfp_no_file(client):
index 4aa7a75060b86ca48d4e43c4e09e14c71c7b6bde..16eded905fcbced4cbba6019cc0a6117583710df 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -1,7 +1,7 @@
 NOW
+- Apply user colors to songs in lists outside profile
 
 SOON
-- Apply user colors to songs in lists outside profile
 - Player minimize button
 - Shuffle all
 - AJAX pages so songs can play during navigation