This commit is contained in:
l.gabrysiak 2025-03-02 12:17:37 +01:00
parent dee0a856e1
commit 4383eee0ba
1 changed files with 8 additions and 2 deletions

View File

@ -9,6 +9,8 @@ from open_webui.models.groups import Groups
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont
import random import random
import base64
from io import BytesIO
from pydantic import BaseModel, ConfigDict from pydantic import BaseModel, ConfigDict
from sqlalchemy import BigInteger, Column, String, Text, JSON from sqlalchemy import BigInteger, Column, String, Text, JSON
@ -346,7 +348,7 @@ class UsersTable:
def generate_letter_image(letter, image_size=(200, 200), font_size=100, font_path=None): def generate_letter_image(letter, image_size=(200, 200), font_size=100, font_path=None):
""" """
Generuje obraz z podaną literą i losowym kolorem tła. Generuje obraz z podaną literą i losowym kolorem tła, zwracając go w formacie base64.
:param letter: Pojedyncza litera do wyświetlenia :param letter: Pojedyncza litera do wyświetlenia
:param image_size: Rozmiar obrazu (szerokość, wysokość) :param image_size: Rozmiar obrazu (szerokość, wysokość)
@ -372,7 +374,11 @@ class UsersTable:
text_y = (image_size[1] - text_height) // 2 text_y = (image_size[1] - text_height) // 2
draw.text((text_x, text_y), letter, font=font, fill=text_color) draw.text((text_x, text_y), letter, font=font, fill=text_color)
return image
buffered = BytesIO()
image.save(buffered, format="PNG")
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
return f"data:image/png;base64,{img_str}"
def update_user_profile(self, id: str, name: str, profile_image_url: str, role: str, permissions: Optional[dict] = None, subscription: Optional[List[str]] = None) -> bool: def update_user_profile(self, id: str, name: str, profile_image_url: str, role: str, permissions: Optional[dict] = None, subscription: Optional[List[str]] = None) -> bool:
try: try: