Go 如何更改图像的分辨率?

Go 如何更改图像的分辨率?,go,go-gin,Go,Go Gin,上传前如何更改此图像的分辨率 f, uploadedFile, err := c.Request.FormFile("file") // image file if err != nil { c.JSON(http.StatusInternalServerError, gin.H{ "message": err.Error(), "error": true, }) return

上传前如何更改此图像的分辨率

f, uploadedFile, err := c.Request.FormFile("file") // image file
if err != nil {
    c.JSON(http.StatusInternalServerError, gin.H{
        "message": err.Error(),
        "error":   true,
    })
    return
}

fullcode:paste.ofcode.org/4wvAGNxZDmpqZ2Zucujmnw

如icza所述,您需要一个外部库来完成此操作,
有一个基本的:它不再被维护
更大的是:

在这两种情况下,在使用调整大小库之前,都需要获得标准图像结构

看起来是这样的:

导入(
“图像”
github.com/dissection/imaging
[...]
)
[...]
f、 uploadedFile,err:=c.Request.FormFile(“文件”)//图像文件
//将文件解码为图像结构
var srcimgimage.image
srcImg,u,err=image.Decode(f)
//将srcImage调整为宽度=800px,保留纵横比。
dstmage800:=imaging.Resize(srcImg,800,0,imaging.Lanczos)

您需要调整图像的大小。标准库不支持图像大小调整,因此请寻找第三方解决方案(关于so的主题外)。