Created
April 18, 2016 17:00
-
-
Save leikind/a745183571703eb48e02da2078605a5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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