mirror of
				https://github.com/Kakune55/Pixel.git
				synced 2025-11-04 05:54:40 +08:00 
			
		
		
		
	调整详细页图片布局大小&增加缩略图大小参数
This commit is contained in:
		@@ -17,12 +17,19 @@
 | 
				
			|||||||
- /idlist 列出所有图片id
 | 
					- /idlist 列出所有图片id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 部分接口文档
 | 
					## 部分接口文档
 | 
				
			||||||
### `/img` `/img/mini` `/del` `/info`
 | 
					### `/img` `/del` `/info`
 | 
				
			||||||
#### 请求方式
 | 
					#### 请求方式
 | 
				
			||||||
Get  
 | 
					Get  
 | 
				
			||||||
#### 请求参数
 | 
					#### 请求参数
 | 
				
			||||||
id 图片id
 | 
					id 图片id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### `/img/mini`
 | 
				
			||||||
 | 
					#### 请求方式
 | 
				
			||||||
 | 
					Get  
 | 
				
			||||||
 | 
					#### 请求参数
 | 
				
			||||||
 | 
					id 图片id
 | 
				
			||||||
 | 
					size 图片横向大小 单位像素 0-1024
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 使用的外部库
 | 
					## 使用的外部库
 | 
				
			||||||
"github.com/disintegration/imaging" MIT LICENSE
 | 
					"github.com/disintegration/imaging" MIT LICENSE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -68,7 +68,7 @@
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #imgshow {
 | 
					    #imgshow {
 | 
				
			||||||
      width: 100%;
 | 
					      max-width: 100%;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #delete-button {
 | 
					    #delete-button {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -77,7 +77,7 @@
 | 
				
			|||||||
          galleryItem.classList.add("gallery-item");
 | 
					          galleryItem.classList.add("gallery-item");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          const img = document.createElement("img");
 | 
					          const img = document.createElement("img");
 | 
				
			||||||
          img.src = `/img/mini?id=${id}`;
 | 
					          img.src = `/img/mini?id=${id}&size=192`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          const infoBox = document.createElement("div");
 | 
					          const infoBox = document.createElement("div");
 | 
				
			||||||
          infoBox.classList.add("info-box");
 | 
					          infoBox.classList.add("info-box");
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										9
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								main.go
									
									
									
									
									
								
							@@ -227,6 +227,13 @@ func generateThumbnail(filePath string, width, height int) (*image.NRGBA, error)
 | 
				
			|||||||
func displayThumbnailHandler(w http.ResponseWriter, r *http.Request) {
 | 
					func displayThumbnailHandler(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
	// 获取请求参数,例如文件名
 | 
						// 获取请求参数,例如文件名
 | 
				
			||||||
	filename := r.FormValue("id")
 | 
						filename := r.FormValue("id")
 | 
				
			||||||
 | 
						imgsize, err := strconv.Atoi(r.FormValue("size"))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
					        http.Error(w, "size参数错误 应为纯数字", http.StatusBadRequest)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
						if imgsize <= 1 || imgsize > 1024 {
 | 
				
			||||||
 | 
					        http.Error(w, "size参数错误 范围应在0-1024之间", http.StatusBadRequest)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
	if filename == "" {
 | 
						if filename == "" {
 | 
				
			||||||
		http.Error(w, "未提供文件名", http.StatusBadRequest)
 | 
							http.Error(w, "未提供文件名", http.StatusBadRequest)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
@@ -236,7 +243,7 @@ func displayThumbnailHandler(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
	filePath := filepath.Join("./data/img", database.GetFileName(filename))
 | 
						filePath := filepath.Join("./data/img", database.GetFileName(filename))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 生成缩略图
 | 
						// 生成缩略图
 | 
				
			||||||
	thumbnail, err := generateThumbnail(filePath, 128, 0) // 设置缩略图的宽度和高度
 | 
						thumbnail, err := generateThumbnail(filePath, imgsize, 0) // 设置缩略图的宽度和高度
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		http.Error(w, "无法生成缩略图", http.StatusInternalServerError)
 | 
							http.Error(w, "无法生成缩略图", http.StatusInternalServerError)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user