后端添加thumbnail接口
parent
ac8850da45
commit
fc4176568e
|
@ -2,12 +2,8 @@
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="7cf7b6b3-0082-44ef-bb0f-bfcc57e19eb1" name="Default Changelist" comment="">
|
<list default="true" id="7cf7b6b3-0082-44ef-bb0f-bfcc57e19eb1" name="Default Changelist" comment="">
|
||||||
<change afterPath="$PROJECT_DIR$/utils/const.go" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/controller/file.go" beforeDir="false" afterPath="$PROJECT_DIR$/controller/file.go" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/controller/file.go" beforeDir="false" afterPath="$PROJECT_DIR$/controller/file.go" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/controller/hardware.go" beforeDir="false" afterPath="$PROJECT_DIR$/controller/hardware.go" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/main.go" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/model/hardware.go" beforeDir="false" afterPath="$PROJECT_DIR$/model/hardware.go" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/disintegration/imaging"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -70,7 +73,7 @@ func (this *FileController) OnUpload(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *FileController) OnDownLoad(c *gin.Context) {
|
func (this *FileController) OnThumbnail(c *gin.Context) {
|
||||||
resp := RespBase{Msg:"FAIL",Status: 211}
|
resp := RespBase{Msg:"FAIL",Status: 211}
|
||||||
|
|
||||||
fileName := c.Param("file")
|
fileName := c.Param("file")
|
||||||
|
@ -79,7 +82,36 @@ func (this *FileController) OnDownLoad(c *gin.Context) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
file,e := os.Open("/home/ubuntu/api/bin/image/" +fileName)
|
// input files
|
||||||
|
files := []string{"/home/ubuntu/api/bin/image/" +fileName}
|
||||||
|
|
||||||
|
// load images and make 100x100 thumbnails of them
|
||||||
|
var thumbnails []image.Image
|
||||||
|
for _, file := range files {
|
||||||
|
img, err := imaging.Open(file)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
thumb := imaging.Thumbnail(img, 100, 100, imaging.CatmullRom)
|
||||||
|
thumbnails = append(thumbnails, thumb)
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a new blank image
|
||||||
|
dst := imaging.New(100*len(thumbnails), 100, color.NRGBA{0, 0, 0, 0})
|
||||||
|
|
||||||
|
// paste thumbnails into the new image side by side
|
||||||
|
for i, thumb := range thumbnails {
|
||||||
|
dst = imaging.Paste(dst, thumb, image.Pt(i*100, 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
// save the combined image to file
|
||||||
|
err := imaging.Save(dst, "/home/ubuntu/api/bin/image/thumbnail_" + fileName)
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// open file
|
||||||
|
file,e := os.Open("/home/ubuntu/api/bin/image/thumbnail_" + fileName)
|
||||||
if nil != e{
|
if nil != e{
|
||||||
log.Print(e.Error())
|
log.Print(e.Error())
|
||||||
c.JSON(200,resp)
|
c.JSON(200,resp)
|
||||||
|
@ -101,7 +133,7 @@ func (this *FileController) OnDownLoad(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (this *FileController) OnThumbnail(c *gin.Context) {
|
func (this *FileController) OnDownLoad(c *gin.Context) {
|
||||||
resp := RespBase{Msg:"FAIL",Status: 211}
|
resp := RespBase{Msg:"FAIL",Status: 211}
|
||||||
|
|
||||||
fileName := c.Param("file")
|
fileName := c.Param("file")
|
||||||
|
|
Loading…
Reference in New Issue