opt: 缩略图生成算法

This commit is contained in:
RockYang 2023-11-28 14:50:19 +08:00
parent ce8fa79206
commit 7a2ffdf39c
6 changed files with 18 additions and 9 deletions

View File

@ -314,10 +314,16 @@ func staticResourceMiddleware() gin.HandlerFunc {
return return
} }
var newImg image.Image
if height == 0 || with == 0 {
// 固定宽度,高度自适应
newImg = resize.Resize(uint(with), uint(height), img, resize.Lanczos3)
} else {
// 生成缩略图 // 生成缩略图
resizedImg := resize.Thumbnail(uint(with), uint(height), img, resize.Lanczos3) newImg = resize.Thumbnail(uint(with), uint(height), img, resize.Lanczos3)
}
var buffer bytes.Buffer var buffer bytes.Buffer
err = jpeg.Encode(&buffer, resizedImg, &jpeg.Options{Quality: quality}) err = jpeg.Encode(&buffer, newImg, &jpeg.Options{Quality: quality})
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -120,7 +120,7 @@ func (h *MidJourneyHandler) Image(c *gin.Context) {
prompt += " --style raw" prompt += " --style raw"
} }
if data.Model != "" && !strings.Contains(prompt, "--v") && !strings.Contains(prompt, "--niji") { if data.Model != "" && !strings.Contains(prompt, "--v") && !strings.Contains(prompt, "--niji") {
prompt += data.Model prompt += fmt.Sprintf(" %s", data.Model)
} }
idValue, _ := c.Get(types.LoginUserID) idValue, _ := c.Get(types.LoginUserID)
@ -348,8 +348,8 @@ func (h *MidJourneyHandler) JobList(c *gin.Context) {
continue continue
} }
if item.Progress < 100 { if item.Progress < 100 {
// 30 分钟还没完成的任务直接删除 // 10 分钟还没完成的任务直接删除
if time.Now().Sub(item.CreatedAt) > time.Minute*30 { if time.Now().Sub(item.CreatedAt) > time.Minute*10 {
h.db.Delete(&item) h.db.Delete(&item)
continue continue
} }

View File

@ -72,6 +72,8 @@ func (s *Service) Run() {
} }
if err != nil { if err != nil {
logger.Error("绘画任务执行失败:", err) logger.Error("绘画任务执行失败:", err)
// 删除任务
s.db.Delete(&model.MidJourneyJob{Id: uint(task.Id)})
// 推送任务到前端 // 推送任务到前端
client := s.Clients.Get(task.SessionId) client := s.Clients.Get(task.SessionId)
if client != nil { if client != nil {

View File

@ -4,6 +4,7 @@
color #ffffff color #ffffff
overflow-x hidden overflow-x hidden
.running-job-list { .running-job-list {
.job-item { .job-item {
//border: 1px solid #454545; //border: 1px solid #454545;

View File

@ -45,9 +45,9 @@ onMounted(() => {
}) })
const computeSize = () => { const computeSize = () => {
const w = container.value.offsetWidth - 8 // const w = container.value.offsetWidth - 10 //
let cols = Math.floor(w / props.width) let cols = Math.floor(w / props.width)
itemWidth.value = Math.ceil(w / cols) itemWidth.value = Math.floor(w / cols)
} }
window.onresize = () => { window.onresize = () => {

View File

@ -259,7 +259,7 @@ const getNext = () => {
// //
const imageList = res.data const imageList = res.data
for (let i = 0; i < imageList.length; i++) { for (let i = 0; i < imageList.length; i++) {
imageList[i]["img_thumb"] = imageList[i]["img_url"] + "?imageView2/4/w/300/q/75" imageList[i]["img_thumb"] = imageList[i]["img_url"] + "?imageView2/4/w/300/h/0/q/75"
} }
if (list.value.length === 0) { if (list.value.length === 0) {
list.value = imageList list.value = imageList