生成缩略图
parent
91c3632040
commit
81d42f9f22
|
|
@ -13,8 +13,12 @@ using OpenAuth.App.ServiceApp;
|
|||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.WebApi;
|
||||
using Quartz;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SqlSugar;
|
||||
|
||||
|
||||
|
||||
namespace OpenAuth.App.BaseApp.Subscribe;
|
||||
|
||||
public class ConfigSubscribe : IJob
|
||||
|
|
@ -261,6 +265,34 @@ public class ConfigSubscribe : IJob
|
|||
.Where(a => a.ObjectKey.Equals(objectKey)).SingleAsync();
|
||||
if (mediaFile == null)
|
||||
{
|
||||
string objectKey1 = data.file.object_key.ToString();
|
||||
string suoluokey = "minipic/" + data.file.name.ToString();
|
||||
//缩略图处理
|
||||
var imageStream = _minioService.GetObjectAsStream("", objectKey1);
|
||||
var width = 0;
|
||||
var height = 0;
|
||||
using (var image = Image.Load(imageStream.Result))
|
||||
{
|
||||
|
||||
width = image.Width;
|
||||
height = image.Height;
|
||||
var thumbnailSize = 100; // 缩略图大小,可以根据需要调整
|
||||
var thumbnail = image.Clone(ctx => ctx.Resize(new ResizeOptions
|
||||
{
|
||||
Size = new Size(thumbnailSize, thumbnailSize),
|
||||
Mode = ResizeMode.Crop // 根据需要选择裁剪或填充模式
|
||||
}));
|
||||
|
||||
// 将缩略图保存到内存流中(为了上传)
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
thumbnail.SaveAsJpeg(memoryStream); // 可以根据需要选择不同的格式,如Png, Bmp等。
|
||||
memoryStream.Position = 0; // 重置流的位置到开始处
|
||||
|
||||
// 上传缩略图到MinIO
|
||||
await _minioService.PutObjectAsync("", data.file.name.ToString(), suoluokey, memoryStream); // 根据实际格式修改Content-Type
|
||||
}
|
||||
}
|
||||
var fileUpload = new LasaMediaFile()
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
|
|
@ -283,7 +315,10 @@ public class ConfigSubscribe : IJob
|
|||
ParentKey = folderKey[2],
|
||||
Tid = result.tid,
|
||||
Bid = result.bid,
|
||||
FlightType = flightType
|
||||
FlightType = flightType,
|
||||
Width = width,
|
||||
Height = height,
|
||||
minipic = suoluokey
|
||||
};
|
||||
// todo 添加事务
|
||||
await _sqlSugarClient.Insertable(fileUpload).ExecuteCommandAsync();
|
||||
|
|
|
|||
|
|
@ -116,4 +116,6 @@ public class LasaMediaFile
|
|||
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public string PicLink { get; set; }
|
||||
|
||||
public string minipic { get; set; }
|
||||
}
|
||||
Loading…
Reference in New Issue