Last active
October 6, 2015 19:48
-
-
Save ajstarks/3044339 to your computer and use it in GitHub Desktop.
Getting the width and height of jpg and png images
This file contains 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" | |
"image" | |
_ "image/jpeg" | |
_ "image/png" | |
"os" | |
) | |
func main() { | |
for _, fname := range os.Args[1:] { | |
f, err := os.Open(fname) | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "%v\n", err) | |
continue | |
} | |
im, _, err := image.DecodeConfig(f) | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "%s: %v\n", fname, err) | |
continue | |
} | |
fmt.Printf("%s %d %d\n", fname, im.Width, im.Height) | |
f.Close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment