Convert image buffers to PNG format on macOS

This commit is contained in:
Mark Qvist 2024-03-19 19:57:48 +01:00
parent 09f849a19d
commit f09e01e065
1 changed files with 13 additions and 0 deletions

View File

@ -40,6 +40,9 @@ else:
from .helpers import ts_format, file_ts_format, mdc from .helpers import ts_format, file_ts_format, mdc
from .helpers import color_received, color_delivered, color_propagated, color_paper, color_failed, color_unknown, intensity_msgs_dark, intensity_msgs_light from .helpers import color_received, color_delivered, color_propagated, color_paper, color_failed, color_unknown, intensity_msgs_dark, intensity_msgs_light
if RNS.vendor.platformutils.is_darwin():
from PIL import Image as PilImage
from kivy.lang.builder import Builder from kivy.lang.builder import Builder
class ListLXMessageCard(MDCard): class ListLXMessageCard(MDCard):
@ -387,6 +390,16 @@ class Messages():
item.image_field = image_field item.image_field = image_field
img = item.ids.message_image img = item.ids.message_image
img.source = "" img.source = ""
# Convert to PNG format on OSX, since support
# for webp seems rather flaky.
if RNS.vendor.platformutils.is_darwin():
im = PilImage.open(io.BytesIO(image_field[1]))
buf = io.BytesIO()
im.save(buf, format="png")
image_field[1] = buf.getvalue()
image_field[0] = "png"
img.texture = CoreImage(io.BytesIO(image_field[1]), ext=image_field[0]).texture img.texture = CoreImage(io.BytesIO(image_field[1]), ext=image_field[0]).texture
img.reload() img.reload()