mirror of
				https://github.com/yangjian102621/geekai.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	opt: 缩略图生成算法
This commit is contained in:
		@@ -314,10 +314,16 @@ func staticResourceMiddleware() gin.HandlerFunc {
 | 
			
		||||
				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
 | 
			
		||||
			err = jpeg.Encode(&buffer, resizedImg, &jpeg.Options{Quality: quality})
 | 
			
		||||
			err = jpeg.Encode(&buffer, newImg, &jpeg.Options{Quality: quality})
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				log.Fatal(err)
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -120,7 +120,7 @@ func (h *MidJourneyHandler) Image(c *gin.Context) {
 | 
			
		||||
		prompt += " --style raw"
 | 
			
		||||
	}
 | 
			
		||||
	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)
 | 
			
		||||
@@ -348,8 +348,8 @@ func (h *MidJourneyHandler) JobList(c *gin.Context) {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		if item.Progress < 100 {
 | 
			
		||||
			// 30 分钟还没完成的任务直接删除
 | 
			
		||||
			if time.Now().Sub(item.CreatedAt) > time.Minute*30 {
 | 
			
		||||
			// 10 分钟还没完成的任务直接删除
 | 
			
		||||
			if time.Now().Sub(item.CreatedAt) > time.Minute*10 {
 | 
			
		||||
				h.db.Delete(&item)
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -72,6 +72,8 @@ func (s *Service) Run() {
 | 
			
		||||
		}
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			logger.Error("绘画任务执行失败:", err)
 | 
			
		||||
			// 删除任务
 | 
			
		||||
			s.db.Delete(&model.MidJourneyJob{Id: uint(task.Id)})
 | 
			
		||||
			// 推送任务到前端
 | 
			
		||||
			client := s.Clients.Get(task.SessionId)
 | 
			
		||||
			if client != nil {
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@
 | 
			
		||||
  color #ffffff
 | 
			
		||||
  overflow-x hidden
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  .running-job-list {
 | 
			
		||||
    .job-item {
 | 
			
		||||
      //border: 1px solid #454545;
 | 
			
		||||
 
 | 
			
		||||
@@ -45,9 +45,9 @@ onMounted(() => {
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
const computeSize = () => {
 | 
			
		||||
  const w = container.value.offsetWidth - 8 // 减去滚动条的宽度
 | 
			
		||||
  const w = container.value.offsetWidth - 10 // 减去滚动条的宽度
 | 
			
		||||
  let cols = Math.floor(w / props.width)
 | 
			
		||||
  itemWidth.value = Math.ceil(w / cols)
 | 
			
		||||
  itemWidth.value = Math.floor(w / cols)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
window.onresize = () => {
 | 
			
		||||
 
 | 
			
		||||
@@ -259,7 +259,7 @@ const getNext = () => {
 | 
			
		||||
    // 生成缩略图
 | 
			
		||||
    const imageList = res.data
 | 
			
		||||
    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) {
 | 
			
		||||
      list.value = imageList
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user