Skip to content

Commit 3a7ef4e

Browse files
committed
修复项目图标上传的BUG
1.BookController.go中344行,拼接上传图片保存路径时未拼接working directory 2.graphics目录下copy.go文件11行,ImageCopy方法增加image.Paletted类型的处理
1 parent acdd2e2 commit 3a7ef4e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

controllers/BookController.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ func (c *BookController) UploadCover() {
340340
fileName := "cover_" + strconv.FormatInt(time.Now().UnixNano(), 16)
341341

342342
//附件路径按照项目组织
343-
filePath := filepath.Join("uploads", book.Identify, "images", fileName+ext)
343+
// filePath := filepath.Join("uploads", book.Identify, "images", fileName+ext)
344+
filePath := filepath.Join(conf.WorkingDirectory, "uploads", book.Identify, "images", fileName+ext)
344345

345346
path := filepath.Dir(filePath)
346347

graphics/copy.go

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ func ImageCopy(src image.Image, x, y, w, h int) (image.Image, error) {
1818
subImg = rgbImg.SubImage(image.Rect(x, y, x+w, y+h)).(*image.RGBA) //图片裁剪x0 y0 x1 y1
1919
} else if rgbImg, ok := src.(*image.NRGBA); ok {
2020
subImg = rgbImg.SubImage(image.Rect(x, y, x+w, y+h)).(*image.NRGBA) //图片裁剪x0 y0 x1 y1
21+
} else if rgbImg, ok := src.(*image.Paletted); ok {
22+
subImg = rgbImg.SubImage(image.Rect(x, y, x+w, y+h)).(*image.Paletted) //图片裁剪x0 y0 x1 y1
2123
} else {
2224

2325
return subImg, errors.New("图片解码失败")

0 commit comments

Comments
 (0)