Skip to content

Instantly share code, notes, and snippets.

@sergiotapia
Last active November 16, 2024 05:40

Revisions

  1. sergiotapia revised this gist Dec 9, 2013. 1 changed file with 16 additions and 16 deletions.
    32 changes: 16 additions & 16 deletions images_dimensions.go
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,27 @@
    package main

    import (
    "fmt"
    "image"
    "os"
    _ "image/jpeg"
    _ "image/png"
    "fmt"
    "image"
    "os"
    _ "image/jpeg"
    _ "image/png"
    )

    func main() {
    width, height := getImageDimension("rainy.jpg")
    fmt.Println("Width:", width, "Height:", height)
    width, height := getImageDimension("rainy.jpg")
    fmt.Println("Width:", width, "Height:", height)
    }

    func getImageDimension(imagePath string) (int, int) {
    file, err := os.Open(imagePath)
    if err != nil {
    fmt.Fprintf(os.Stderr, "%v\n", err)
    }
    file, err := os.Open(imagePath)
    if err != nil {
    fmt.Fprintf(os.Stderr, "%v\n", err)
    }

    image, _, err := image.DecodeConfig(file)
    if err != nil {
    fmt.Fprintf(os.Stderr, "%s: %v\n", imagePath, err)
    }
    return image.Width, image.Height
    image, _, err := image.DecodeConfig(file)
    if err != nil {
    fmt.Fprintf(os.Stderr, "%s: %v\n", imagePath, err)
    }
    return image.Width, image.Height
    }
  2. sergiotapia created this gist Dec 9, 2013.
    27 changes: 27 additions & 0 deletions images_dimensions.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    package main

    import (
    "fmt"
    "image"
    "os"
    _ "image/jpeg"
    _ "image/png"
    )

    func main() {
    width, height := getImageDimension("rainy.jpg")
    fmt.Println("Width:", width, "Height:", height)
    }

    func getImageDimension(imagePath string) (int, int) {
    file, err := os.Open(imagePath)
    if err != nil {
    fmt.Fprintf(os.Stderr, "%v\n", err)
    }

    image, _, err := image.DecodeConfig(file)
    if err != nil {
    fmt.Fprintf(os.Stderr, "%s: %v\n", imagePath, err)
    }
    return image.Width, image.Height
    }