测试动图gif成功

master
DESKTOP-4RNDQIC\29019 2021-02-03 01:47:01 +08:00
parent 97962d0145
commit 738184fa47
2 changed files with 56 additions and 27 deletions

View File

@ -50,18 +50,18 @@ func GetArticles(c *gin.Context) {
if req.Type == 110 {
is_public := 0
if public == "true" {
is_public = 0
} else {
is_public = 1
} else {
is_public = 0
}
sql = "select * from doc where doc.title like '%%%s%%' and is_public = %d limit %d offset %d "
sql = fmt.Sprintf(sql, req.Name, is_public, limit, offset*limit)
} else {
is_public := 0
if public == "true" {
is_public = 0
} else {
is_public = 1
} else {
is_public = 0
}
sql = fmt.Sprintf("select * from doc where doc.title like '%%%s%%' and doc.type = %d and is_public = %d limit %d offset %d ",
req.Name, req.Type, is_public, limit, offset*limit)

View File

@ -12,8 +12,10 @@ import (
"log"
"net/http"
"os"
"github.com/nfnt/resize"
"image/jpeg"
// "github.com/nfnt/resize"
// "image/jpeg"
"image/gif"
// "strings"
)
type FileController struct {
@ -31,28 +33,55 @@ func (this *FileController) OnUpload(c *gin.Context) {
log.Print(err.Error())
return
}
img, name, err := image.Decode(file)
bound := img.Bounds()
dx := bound.Dx()
dy := bound.Dy()
log.Printf("%d %d %s",dx,dy,name)
if err != nil {
log.Print(err)
}
// resize to width 1000 using Lanczos resampling
// and preserve aspect ratio
if(dx > 800){
dx = dx / 2;
}
m := resize.Resize(uint(dx), 0, img, resize.Lanczos3)
// config, name, err := image.DecodeConfig(file)
// dx := config.Width
// log.Print(config.Width,name)
// if err != nil {
// if strings.Contains(err.Error(),"gif") {
datout, err := os.Create("image/" + uid.String() + "." + name)
// }else{
// log.Print(err.Error())
// // return
// }
// }
// if name == "gif"{
allgifs,er := gif.DecodeAll(file)
if nil != er{
log.Print("decode error",er.Error())
return
}
datout, err := os.Create("image/" + uid.String() + ".jpg" )
defer datout.Close()
if err != nil {
log.Fatal(err)
return
}
jpeg.Encode(datout, m, nil)
c.JSON(200, map[string] interface{}{"url":uid.String() + "." + name } )
gif.EncodeAll(datout,allgifs)
c.JSON(200, map[string] interface{}{"url":uid.String() + ".jpg" } )
// }else{
// img, _, err := image.Decode(file)
// if nil != err{
// log.Print(err.Error())
// return
// }
// // resize to width 1000 using Lanczos resampling
// // and preserve aspect ratio
// if(dx > 800){
// dx = dx / 2;
// }
// m := resize.Resize(uint(dx), 0, img, resize.Lanczos3)
// datout, err := os.Create("image/" + uid.String() + "." + name)
// defer datout.Close()
// if err != nil {
// log.Fatal(err)
// }
// jpeg.Encode(datout, m, nil)
// c.JSON(200, map[string] interface{}{"url":uid.String() + "." + name } )
// }
}