Created
March 28, 2016 14:17
-
-
Save alfredwesterveld/0b8fb5faa2df22781092 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 ( | |
| "github.com/nfnt/resize" | |
| "image/png" | |
| "log" | |
| "os" | |
| ) | |
| func main() { | |
| file, err := os.Open("image_1.png") | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| // decode jpeg into image.Image | |
| img, err := png.Decode(file) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| file.Close() | |
| // resize to width 1000 using Lanczos resampling | |
| // and preserve aspect ratio | |
| m := resize.Resize(437, 315, img, resize.Lanczos3) | |
| out, err := os.Create("test_resized.png") | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| defer out.Close() | |
| // write new image to file | |
| png.Encode(out, m) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment