Imaging is a simple image processing package for Go
译文:Imaging是一个简单图像处理的Go语言包
文档:
- https://github.com/disintegration/imaging
- https://pkg.go.dev/github.com/disintegration/imaging
- Go Image Filtering Toolkit: https://github.com/disintegration/gift
安装
go get github.com/disintegration/imaging
代码示例
package main
import (
"log"
"github.com/disintegration/imaging"
)
func main() {
// 打开一个图片文件
src, err := imaging.Open("./image.jpg")
if err != nil {
log.Fatalf("failed to open image: %v", err)
}
// 生成缩略图
dst := imaging.Thumbnail(src, 100, 100, imaging.Lanczos)
// 保存
err = imaging.Save(dst, "thumbnail.jpg")
if err != nil {
log.Fatalf("failed to save image: %v", err)
}
}
处理前 image.jpg 74.58kb 处理后 thumbnail.jpg 7.80kb