rwcarlsen / goexif

Decode embedded EXIF meta data from image files.
BSD 2-Clause "Simplified" License
623 stars 134 forks source link

exif: failed to find exif intro marker #89

Open eliassama opened 8 months ago

eliassama commented 8 months ago

I need to extract exif from ai generated image.

like this:

5242974a

eliassama commented 8 months ago

this is my demo

package main

import (
    "fmt"
    "github.com/rwcarlsen/goexif/exif"
    "os"
)

func ReadOrientation(filename string) int {
    file, err := os.Open(filename)
    if err != nil {
        fmt.Println("failed to open file, err: ", err)
        return 0
    }
    defer file.Close()

    x, err := exif.Decode(file)
    if err != nil {
        fmt.Println("failed to decode file, err: ", err)
        return 0
    }

    orientation, err := x.Get(exif.Orientation)
    if err != nil {
        fmt.Println("failed to get orientation, err: ", err)
        return 0
    }
    orientVal, err := orientation.Int(0)
    if err != nil {
        fmt.Println("failed to convert type of orientation, err: ", err)
        return 0
    }

    fmt.Println("the value of photo orientation is :", orientVal)
    return orientVal
}

func main() {
    ReadOrientation("5242974a.png")
}

they report :failed to decode file, err: exif: failed to find exif intro marker