feat: Thumbnail-Varianten (256px) für Agent-Avatare und Session-Images
- ImageService: ResizeDataUrlSmall() für 256px WebP-Thumbnails (Quality 70) - Neue DB-Spalten: agents.avatar_small, sessions.image_small - Migration generiert Thumbnails für bestehende Bilder automatisch - Listen-Endpoints (/api/agents, /api/sessions) liefern kleine Variante - Detail-Endpoints liefern weiterhin das volle 512px-Bild - Frontend unverändert (Cards nutzen automatisch die kleineren Bilder)
This commit is contained in:
1 parent
8efce5f2d5
commit
2a2e98ca68
6 files changed
+116
-15
No files matched your search
@@ -9,7 +9,9 @@ namespace Gott.Services;
|
||||
public class ImageService
|
||||
{
|
||||
private const int MaxSideLength = 512;
|
||||
private const int SmallSideLength = 256;
|
||||
private const int WebPQuality = 80;
|
||||
private const int WebPQualitySmall = 70;
|
||||
|
||||
/// <summary>
|
||||
/// Nimmt eine Base64-Data-URL (z.B. "data:image/png;base64,..."), skaliert das Bild
|
||||
@@ -17,6 +19,20 @@ public class ImageService
|
||||
/// Gibt null zurück wenn input null/leer ist.
|
||||
/// </summary>
|
||||
public string ResizeDataUrl(string dataUrl)
|
||||
{
|
||||
return ResizeToWebP(dataUrl, MaxSideLength, WebPQuality);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Erzeugt eine kleine Thumbnail-Variante (max 256px, Quality 70) für Dashboard-Listen.
|
||||
/// Gibt null zurück wenn input null/leer ist.
|
||||
/// </summary>
|
||||
public string ResizeDataUrlSmall(string dataUrl)
|
||||
{
|
||||
return ResizeToWebP(dataUrl, SmallSideLength, WebPQualitySmall);
|
||||
}
|
||||
|
||||
private static string ResizeToWebP(string dataUrl, int maxSide, int quality)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dataUrl)) return null;
|
||||
|
||||
@@ -30,18 +46,18 @@ public class ImageService
|
||||
using var image = Image.Load(bytes);
|
||||
|
||||
// Skalieren wenn nötig
|
||||
if (image.Width > MaxSideLength || image.Height > MaxSideLength)
|
||||
if (image.Width > maxSide || image.Height > maxSide)
|
||||
{
|
||||
image.Mutate(x => x.Resize(new ResizeOptions
|
||||
{
|
||||
Size = new Size(MaxSideLength, MaxSideLength),
|
||||
Size = new Size(maxSide, maxSide),
|
||||
Mode = ResizeMode.Max
|
||||
}));
|
||||
}
|
||||
|
||||
// Immer als WebP encodieren
|
||||
using var ms = new MemoryStream();
|
||||
image.Save(ms, new WebpEncoder { Quality = WebPQuality });
|
||||
image.Save(ms, new WebpEncoder { Quality = quality });
|
||||
var webpBase64 = Convert.ToBase64String(ms.ToArray());
|
||||
|
||||
return "data:image/webp;base64," + webpBase64;
|
||||
|
||||
Reference in new issue
Block a user