golang使用nfnt缩放图片

栏目: Go · 发布时间: 6年前

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("------------------")
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Graph Algorithms

Graph Algorithms

Shimon Even / Cambridge University Press / 2011-9-19 / USD 32.99

Shimon Even's Graph Algorithms, published in 1979, was a seminal introductory book on algorithms read by everyone engaged in the field. This thoroughly revised second edition, with a foreword by Richa......一起来看看 《Graph Algorithms》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

随机密码生成器
随机密码生成器

多种字符组合密码