Fix "Unknown image format" error when showing or updating profiles

wx only decodes the image formats its own handlers support. Mastodon
instances commonly serve avatars and headers as WebP, so wx.Image failed
and raised a modal "Unknown image format" dialog, which blocked the user
from updating their profile or from reading someone's profile.

Images are now decoded with Pillow and their raw pixel data handed over
to wx, through a new mysc.image_utils module shared by the Mastodon and
Bluesky profile dialogs. Undecodable or unreachable images log the
problem and leave an empty placeholder instead of raising.

Also accept WebP and JPEG files in the header/avatar file pickers, warn
the user with a common message dialog when the picked file cannot be
read, and fix the parentless wx.StaticBitmap placeholders that were
created when a profile image could not be downloaded.
This commit is contained in:
Juanjo M
2026-08-02 15:08:25 +01:00
parent 130afe3432
commit b6681df03c
8 changed files with 241 additions and 42 deletions
+7 -7
View File
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
"""Wx dialogs for showing a user's profile."""
from io import BytesIO
from pubsub import pub
from typing import Tuple
import requests
@@ -10,6 +9,7 @@ from logging import getLogger
from threading import Thread
from sessions.mastodon.utils import html_filter
from mysc.image_utils import load_scaled_image
log = getLogger(__name__)
@@ -229,11 +229,11 @@ class ShowUserProfile(wx.Dialog):
"""Draws images on the bitmap ui"""
# log.debug("Drawing images...")
# Header
headerImage = wx.Image(BytesIO(headerImageBytes), wx.BITMAP_TYPE_ANY)
headerImage.Rescale(300, 100, wx.IMAGE_QUALITY_HIGH)
self.headerImage.SetBitmap(headerImage.ConvertToBitmap())
headerImage = load_scaled_image(headerImageBytes, 300, 100)
if headerImage is not None:
self.headerImage.SetBitmap(headerImage.ConvertToBitmap())
# Avatar
avatarImage = wx.Image(BytesIO(avatarImageBytes), wx.BITMAP_TYPE_ANY)
avatarImage.Rescale(150, 150, wx.IMAGE_QUALITY_HIGH)
self.avatarImage.SetBitmap(avatarImage.ConvertToBitmap())
avatarImage = load_scaled_image(avatarImageBytes, 150, 150)
if avatarImage is not None:
self.avatarImage.SetBitmap(avatarImage.ConvertToBitmap())