🐛 Fix analyzer calculating ratio
This commit is contained in:
parent
ed9b1474fb
commit
4cecbd8e4b
@ -99,8 +99,21 @@ func ScanUnanalyzedFileFromDatabase() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateAspectRatio(width, height int, orientation string) float64 {
|
func parseExifOrientation(output string) (int, error) {
|
||||||
if orientation == "6" || orientation == "8" {
|
parts := strings.Fields(output)
|
||||||
|
if len(parts) < 2 {
|
||||||
|
return 0, fmt.Errorf("unexpected format: %s", output)
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
switch orientation {
|
||||||
|
case 5, 6, 7, 8:
|
||||||
width, height = height, width
|
width, height = height, width
|
||||||
}
|
}
|
||||||
return float64(width) / float64(height)
|
return float64(width) / float64(height)
|
||||||
@ -173,7 +186,8 @@ func AnalyzeAttachment(file models.Attachment) error {
|
|||||||
for _, data := range exif {
|
for _, data := range exif {
|
||||||
for k := range data.Fields {
|
for k := range data.Fields {
|
||||||
if k == "Orientation" {
|
if k == "Orientation" {
|
||||||
file.Metadata["ratio"] = calculateAspectRatio(width, height, data.Fields[k].(string))
|
ori, _ := parseExifOrientation(data.Fields[k].(string))
|
||||||
|
file.Metadata["ratio"] = calculateAspectRatio(width, height, ori)
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(k, "GPS") {
|
if strings.HasPrefix(k, "GPS") {
|
||||||
data.Clear(k)
|
data.Clear(k)
|
||||||
@ -217,7 +231,8 @@ func AnalyzeAttachment(file models.Attachment) error {
|
|||||||
for _, data := range exif {
|
for _, data := range exif {
|
||||||
for k := range data.Fields {
|
for k := range data.Fields {
|
||||||
if k == "Orientation" {
|
if k == "Orientation" {
|
||||||
file.Metadata["ratio"] = calculateAspectRatio(stream.Width, stream.Height, data.Fields[k].(string))
|
ori, _ := parseExifOrientation(data.Fields[k].(string))
|
||||||
|
file.Metadata["ratio"] = calculateAspectRatio(stream.Width, stream.Height, ori)
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(k, "GPS") {
|
if strings.HasPrefix(k, "GPS") {
|
||||||
data.Clear(k)
|
data.Clear(k)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user