|
@@ -1,11 +1,16 @@
|
|
|
|
+using Azure.Storage.Blobs.Models;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
|
+using System.Drawing.Imaging;
|
|
|
|
+using System.IO;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Text.Json;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
|
|
+using TEAMModelOS.Models.Request;
|
|
using TEAMModelOS.SDK.DI;
|
|
using TEAMModelOS.SDK.DI;
|
|
|
|
+using TEAMModelOS.SDK.PngQuant;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers.Core
|
|
namespace TEAMModelOS.Controllers.Core
|
|
{
|
|
{
|
|
@@ -21,9 +26,23 @@ namespace TEAMModelOS.Controllers.Core
|
|
}
|
|
}
|
|
|
|
|
|
[HttpPost("image-quant")]
|
|
[HttpPost("image-quant")]
|
|
- public async Task<IActionResult> ImageQuang(JsonElement request)
|
|
|
|
- {
|
|
|
|
- if (!request.TryGetProperty("id_token", out JsonElement id_token)) return BadRequest();
|
|
|
|
|
|
+ public async Task<IActionResult> ImageQuang(List<ImageQuangRequest> request)
|
|
|
|
+ {
|
|
|
|
+ if (request.Count < 1) return BadRequest();
|
|
|
|
+ List<object> respons = new List<object>();
|
|
|
|
+ var quantizer = new PngQuantizer();
|
|
|
|
+ foreach (var item in request)
|
|
|
|
+ {
|
|
|
|
+ using var quantized = quantizer.QuantizeImageFromBase64(item.base64, item.width, item.height);
|
|
|
|
+ using var ms = new MemoryStream();
|
|
|
|
+ quantized.Save(ms, ImageFormat.Png);
|
|
|
|
+ byte[] data = ms.ToArray();
|
|
|
|
+ string base64 = Convert.ToBase64String(data);
|
|
|
|
+ var name = $"{Guid.NewGuid().ToString("N")}.png";
|
|
|
|
+ respons.Add(new { base64 = base64, blob = name });
|
|
|
|
+ //await _azureStorage.GetBlobContainerClient(item.blob).GetBlobClient(name).UploadAsync(ms, new BlobHttpHeaders { ContentType = "image/png" });
|
|
|
|
+ // await _azureStorage.GetBlobContainerClient(item.blob).UploadBlobAsync()
|
|
|
|
+ }
|
|
|
|
|
|
return Ok();
|
|
return Ok();
|
|
}
|
|
}
|