Save EXIF data to the database again.
This commit is contained in:
parent
edd9bdcadc
commit
783910be50
1 changed files with 14 additions and 5 deletions
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/rwcarlsen/goexif/exif"
|
"github.com/rwcarlsen/goexif/exif"
|
||||||
|
"github.com/rwcarlsen/goexif/tiff"
|
||||||
//exif "github.com/rwcarlsen/goexif/exif"
|
//exif "github.com/rwcarlsen/goexif/exif"
|
||||||
//"github.com/dsoprea/go-exif-extra/format"
|
//"github.com/dsoprea/go-exif-extra/format"
|
||||||
)
|
)
|
||||||
|
|
@ -48,6 +49,10 @@ type ImageUpload struct {
|
||||||
UUID uuid.UUID
|
UUID uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *ExifCollection) Walk(name exif.FieldName, tag *tiff.Tag) error {
|
||||||
|
e.Tags[string(name)] = tag.String()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
func extractExif(content_type string, file_bytes []byte) (result *ExifCollection, err error) {
|
func extractExif(content_type string, file_bytes []byte) (result *ExifCollection, err error) {
|
||||||
/*
|
/*
|
||||||
Using "github.com/evanoberholster/imagemeta"
|
Using "github.com/evanoberholster/imagemeta"
|
||||||
|
|
@ -62,18 +67,22 @@ func extractExif(content_type string, file_bytes []byte) (result *ExifCollection
|
||||||
return result, err
|
return result, err
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exif, err := exif.Decode(bytes.NewReader(file_bytes))
|
e, err := exif.Decode(bytes.NewReader(file_bytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "exif: failed to find exif intro marker" {
|
if err.Error() == "exif: failed to find exif intro marker" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("Failed to decode image meta: %w", err)
|
return nil, fmt.Errorf("Failed to decode image meta: %w", err)
|
||||||
}
|
}
|
||||||
lat, lng, _ := exif.LatLong()
|
lat, lng, _ := e.LatLong()
|
||||||
result.GPS = &GPS{
|
result = &ExifCollection{
|
||||||
Latitude: lat,
|
GPS: &GPS{
|
||||||
Longitude: lng,
|
Latitude: lat,
|
||||||
|
Longitude: lng,
|
||||||
|
},
|
||||||
|
Tags: make(map[string]string, 0),
|
||||||
}
|
}
|
||||||
|
err = e.Walk(result)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue