mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-09-19 10:08:03 +08:00
压缩头像
This commit is contained in:
@@ -2,17 +2,18 @@ package graphics
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/gif"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"image/gif"
|
||||
)
|
||||
|
||||
// 将图片保存到指定的路径
|
||||
func SaveImage(p string, src image.Image) error {
|
||||
|
||||
f, err := os.OpenFile( p, os.O_SYNC | os.O_RDWR | os.O_CREATE, 0666)
|
||||
f, err := os.OpenFile(p, os.O_SYNC|os.O_RDWR|os.O_CREATE, 0666)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -22,11 +23,12 @@ func SaveImage(p string, src image.Image) error {
|
||||
|
||||
if strings.EqualFold(ext, ".jpg") || strings.EqualFold(ext, ".jpeg") {
|
||||
|
||||
err = jpeg.Encode(f, src, &jpeg.Options{Quality : 100 })
|
||||
err = jpeg.Encode(f, src, &jpeg.Options{Quality: 80})
|
||||
|
||||
} else if strings.EqualFold(ext, ".png") {
|
||||
err = png.Encode(f, src)
|
||||
} else if strings.EqualFold(ext, ".gif") {
|
||||
err = gif.Encode(f, src, &gif.Options{NumColors : 256})
|
||||
err = gif.Encode(f, src, &gif.Options{NumColors: 256})
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user