Compare commits

..

2 Commits

Author SHA1 Message Date
jhc
7ae08e10f4 Merge branch 'dev' of https://gitea-net.fontree.cn/fiee/fonchain-fiee into dev 2025-02-24 18:12:16 +08:00
jhc
9491b48848 修改 2025-02-24 18:09:52 +08:00
3 changed files with 62 additions and 9 deletions

View File

@ -48,6 +48,19 @@ func ReadOrientation(filename string) (direct int, err error) {
return
}
// 旋转90度
func Rotate90(m image.Image) image.Image {
rotate90 := image.NewRGBA(image.Rect(0, 0, m.Bounds().Dy(), m.Bounds().Dx()))
// 矩阵旋转
for x := m.Bounds().Min.Y; x < m.Bounds().Max.Y; x++ {
for y := m.Bounds().Max.X - 1; y >= m.Bounds().Min.X; y-- {
// 设置像素点
rotate90.Set(m.Bounds().Max.Y-x, y, m.At(y, x))
}
}
return rotate90
}
// 旋转90度
func rotate90(m image.Image) image.Image {
rotate90 := image.NewRGBA(image.Rect(0, 0, m.Bounds().Dy(), m.Bounds().Dx()))
@ -158,3 +171,32 @@ func (u *Upload) PutBos(filePath string, mediaType string, needRemove bool) (url
url = fmt.Sprintf("%s/%s", config.ConfigData.Oss.CdnHost, objectName)
return
}
func MakeThumbnailDefault90(imagePath, savePath string) error {
prefix := strings.ToLower(path.Ext("./2.jpg"))
file, _ := os.Open(imagePath)
defer file.Close()
img, _, err := image.Decode(file)
if err != nil {
return err
}
img = rotate90(img)
newImg, _ := os.Create(savePath)
defer newImg.Close()
switch prefix {
case ".jpg", ".jpeg":
err = jpeg.Encode(newImg, img, &jpeg.Options{Quality: 100})
case "png":
err = png.Encode(newImg, img)
case "bmp":
err = bmp.Encode(newImg, img)
default:
err = jpeg.Encode(newImg, img, &jpeg.Options{Quality: 100})
}
if err != nil {
logger.Error("Encode err", err)
return err
}
return nil
}

View File

@ -1,15 +1,16 @@
package model
const (
HttpType = "http://"
HttpsType = "https://"
TmpArtworkDir = "./runtime/tmp/artworks"
TmpArtistDir = "./runtime/tmp/artists"
MediaPath = "./runtime/"
TplPath = "./data/"
ImgActionRotate = "rotate" //旋转
MediaTypeVideo = "video"
MediaTypeImage = "video"
HttpType = "http://"
HttpsType = "https://"
TmpArtworkDir = "./runtime/tmp/artworks"
TmpArtistDir = "./runtime/tmp/artists"
MediaPath = "./runtime/"
TplPath = "./data/"
ImgActionRotate = "rotate" //旋转
ImgActionRotate90 = "rotate90" //旋转
MediaTypeVideo = "video"
MediaTypeImage = "video"
)
const (

View File

@ -135,6 +135,16 @@ func UploadImg(c *gin.Context) {
_ = os.Remove(dst)
dst = newDst
}
} else if action == model.ImgActionRotate90 {
fileFullName = fmt.Sprintf("%s%s", filename, fileExt)
newDst := fmt.Sprintf("%s/%s_rotate%v", imgPath, filename, fileExt)
if err = logic.MakeThumbnailDefault90(dst, newDst); err != nil {
//ResponseQuickMsg(c, e.Failed, e.GetMsg(e.ERROR_ROTATE_IMG), nil)
//return
} else {
_ = os.Remove(dst)
dst = newDst
}
}
//localUrl := fmt.Sprintf("%s/%s/%s/%s/%s", config.ServerDM, BaseRoute, source, mask, fileFullName)
var data map[string]string = make(map[string]string, 2)