🐛 Analyzer now can handle EXIF Orientation

This commit is contained in:
LittleSheep 2025-01-21 12:27:30 +08:00
parent d0d14d7c67
commit ac347540b8

View File

@ -99,6 +99,13 @@ func ScanUnanalyzedFileFromDatabase() {
}()
}
func calculateAspectRatio(width, height int, orientation int) float64 {
if orientation == 6 || orientation == 8 {
width, height = height, width
}
return float64(width) / float64(height)
}
func AnalyzeAttachment(file models.Attachment) error {
if file.Destination != models.AttachmentDstTemporary {
return fmt.Errorf("attachment isn't in temporary storage, unable to analyze")
@ -133,7 +140,7 @@ func AnalyzeAttachment(file models.Attachment) error {
"Model", "ShutterSpeed", "ISO", "Megapixels", "Aperture",
"ColorSpace", "ColorTemperature", "ColorTone", "Contrast",
"ExposureTime", "FNumber", "FocalLength", "Flash", "HDREffect",
"LensModel",
"LensModel", "Orientation",
}
switch strings.SplitN(file.MimeType, "/", 2)[0] {
@ -165,6 +172,9 @@ func AnalyzeAttachment(file models.Attachment) error {
exif := et.ExtractMetadata(dst)
for _, data := range exif {
for k := range data.Fields {
if k == "Orientation" {
file.Metadata["ratio"] = calculateAspectRatio(width, height, data.Fields[k].(int))
}
if strings.HasPrefix(k, "GPS") {
data.Clear(k)
} else if lo.Contains(exifWhitelist, k) {
@ -206,6 +216,9 @@ func AnalyzeAttachment(file models.Attachment) error {
exif := et.ExtractMetadata(dst)
for _, data := range exif {
for k := range data.Fields {
if k == "Orientation" {
file.Metadata["ratio"] = calculateAspectRatio(stream.Width, stream.Height, data.Fields[k].(int))
}
if strings.HasPrefix(k, "GPS") {
data.Clear(k)
} else if lo.Contains(exifWhitelist, k) {