Skip to content

Instantly share code, notes, and snippets.

@leikind
Created Apr 18, 2016
Embed
What would you like to do?
package main
import (
"fmt"
"github.com/nfnt/resize"
"image/jpeg"
"io"
"os"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func resizeJpeg(writer io.Writer, reader io.Reader, width uint) error {
image, e := jpeg.Decode(reader)
check(e)
resizedImage := resize.Resize(width, 0, image, resize.Lanczos3)
return jpeg.Encode(writer, resizedImage, nil)
}
func main() {
fmt.Printf("%s => %s\n", os.Args[1], os.Args[2])
reader, e := os.Open(os.Args[1])
check(e)
out, e := os.Create(os.Args[2])
check(e)
defer out.Close()
defer reader.Close()
resizeJpeg(out, reader, 800)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment