Skip to content

Commit

Permalink
🐛 Fix analyzer again...
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleSheep2Code committed Jan 21, 2025
1 parent 4cecbd8 commit 1a9e670
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions pkg/internal/services/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,27 @@ func ScanUnanalyzedFileFromDatabase() {
}()
}

func parseExifOrientation(output string) (int, error) {
parts := strings.Fields(output)
if len(parts) < 2 {
return 0, fmt.Errorf("unexpected format: %s", output)
func parseExifOrientation(src string) int {
switch src {
case "Horizontal":
return 1
case "Mirror horizontal":
return 2
case "Rotate 180":
return 3
case "Mirror vertical":
return 4
case "Mirror horizontal and rotate 270 CW":
return 5
case "Rotate 90 CW":
return 6
case "Mirror horizontal and rotate 90 CW":
return 7
case "Rotate 270 CW":
return 8
default:
return 0
}
orientation, err := strconv.Atoi(parts[len(parts)-1])
if err != nil {
return 0, fmt.Errorf("invalid orientation value: %s", parts[len(parts)-1])
}
return orientation, nil
}

func calculateAspectRatio(width, height int, orientation int) float64 {
Expand Down Expand Up @@ -186,7 +197,7 @@ func AnalyzeAttachment(file models.Attachment) error {
for _, data := range exif {
for k := range data.Fields {
if k == "Orientation" {
ori, _ := parseExifOrientation(data.Fields[k].(string))
ori := parseExifOrientation(data.Fields[k].(string))
file.Metadata["ratio"] = calculateAspectRatio(width, height, ori)
}
if strings.HasPrefix(k, "GPS") {
Expand Down Expand Up @@ -231,7 +242,7 @@ func AnalyzeAttachment(file models.Attachment) error {
for _, data := range exif {
for k := range data.Fields {
if k == "Orientation" {
ori, _ := parseExifOrientation(data.Fields[k].(string))
ori := parseExifOrientation(data.Fields[k].(string))
file.Metadata["ratio"] = calculateAspectRatio(stream.Width, stream.Height, ori)
}
if strings.HasPrefix(k, "GPS") {
Expand Down

0 comments on commit 1a9e670

Please sign in to comment.