go-exif
go-exif copied to clipboard
Read all EXIF tags in file
Hi author and contributors,
I am really happy to see that v3 has been released with many support for the way reading EXIF. I made this issue to ask some questions about finding all EXIF data of an image file:
To find all EXIF data, I tried to iterate over all blocks which are likely to have EXIF using the following code:
(ErrInvalidMaxBlock is nothing but my self-defined error)
func GetAllExifData(imageData []byte, so *ScanOptions, maxBlock int) (exifTags []ExifTag, blockRead int, err error) {
defer func() {
if state := recover(); state != nil {
err = log.Wrap(state.(error))
}
}()
if maxBlock < -1 {
return nil, 0, ErrInvalidMaxBlock
}
for n := 0; maxBlock == -1 || n < maxBlock; n++ {
exifData, err := exif.SearchAndExtractExif(imageData)
if err != nil {
if errors.Is(err, exif.ErrNoExif) {
if n == 0 {
return exifTags, blockRead, nil
}
break
}
log.Panic(err)
}
// help find next EXIF without searching from start
imageData = exifData[ExifSignatureLength:]
entries, _, err := GetFlatExifDataUniversalSearch(exifData, so, true)
if err != nil {
if log.Is(err, io.EOF) || log.Is(err, io.ErrUnexpectedEOF) {
continue
}
log.PanicIf(err)
}
blockRead++
exifTags = append(exifTags, entries...)
}
return exifTags, blockRead, nil
}
I would like to ask 2 questions:
-
Do I missed anything while brute-forcing for EXIF block? The library offers me
SearchAndExtractExifN
, but when I want to iterate faster, I think I need to reduce the array size that way. -
When I
GetFlatExifDataUniversalSearch
for the block, sometimes I get
TagId=[0x0004] TagName=[GPSLongitude] Value=[[68 0 192 92 276 204 0 0 3 0 8 8 160 65535 0 32 0 0 1 0 0 276 204 84 0 0 248 0 0 65535 65535 0 0 0]]
Have seen one issue that mentioned this wrong entry, but how could I skip this wrong entry?
Hope you all have a nice day!