nfnt地址 https://github.com/nfnt/resize
package main
import (
"fmt"
"github.com/nfnt/resize"
"image/jpeg"
"log"
"os"
)
func main() {
// open "test.jpg"
file, err := os.Open("C:\\Users\\cixu\\Desktop\\1\\5.jpg")
if err != nil {
log.Fatal(err)
}
// decode jpeg into image.Image
img, err := jpeg.Decode(file)
if err != nil {
log.Fatal(err)
}
file.Close()
// resize to width 1000 using Lanczos resampling
// and preserve aspect ratio
kuan:=img.Bounds().Dx()//
gao:=img.Bounds().Dy()//
fmt.Println(kuan)
fmt.Println(gao)
m := resize.Resize(uint(kuan), 0, img, resize.Lanczos3)
//m := resize.Resize(1000, 0, img, resize.Lanczos3)
out, err := os.Create("C:\\Users\\cixu\\Desktop\\1\\5-2.jpg")
if err != nil {
log.Fatal(err)
}
defer out.Close()
// write new image to file
jpeg.Encode(out, m, nil)
fmt.Println("------------------")
}
有疑问加站长微信联系(非本文作者)