Skip to content

Instantly share code, notes, and snippets.

@ajstarks
Last active October 6, 2015 19:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajstarks/3044339 to your computer and use it in GitHub Desktop.
Save ajstarks/3044339 to your computer and use it in GitHub Desktop.
Getting the width and height of jpg and png images
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