waschinski / photo-stream

Self-hosted, super simple photo stream
https://github.com/waschinski/photo-stream
MIT License
449 stars 70 forks source link

Photos not sorting based on exif data #5

Closed danbush closed 3 years ago

danbush commented 3 years ago

I was about to see if I should just fork the repo in case this was a conscious decision, but I found a commit that shows it was not. From what I can tell, it is possibly sorting based of file modified date rather than exif data?

example: https://danbush.photos/ , all the BLM photos are from 2020 (and I confirmed by looking at the exif data in an exif viewer), and that big leaf photo (https://danbush.photos/dscf9180) is from 2021.

danbush commented 3 years ago

Okay I think I figured out the situation. https://github.com/waschinski/photo-stream/blob/34db56bd668cc909ddfdcd5d17068bd21637fc2b/_plugins/photo_filter.rb#L9 exif date_time is essentially file creation date, whereas SubExif.DateTimeOriginal (at least using exiftool, the formatting is probably different for EXIFR) is actually the date the photo was taken.

danbush commented 3 years ago

I think

EXIFR::JPEG.new(photo.path).date_time_original.to_s

will actually solve it perhaps.

danbush commented 3 years ago

Fixed it on my local version by setting line 7 to this:

sorted = photos.sort_by { |photo| EXIFR::JPEG.new(photo.path).date_time_original.to_s }

and line 9 to this

exifr::JPEG.new(photo.path).date_time_original.to_s
waschinski commented 3 years ago

Thanks for raising this issue as well as including a solution on how to fix it. I have run some more tests and the current implementation really is lacking.

I ended up fixing it with a slightly more complex logic though. The sorting will now check if the photo actually does have EXIF information at all and only use the original date time from that if it is also set. Otherwise the fallback will still be the file modification date.

Feel free to check out the commit and let me know if this solution makes sense.

danbush commented 3 years ago

Makes sense, thank you!