Photos: Sorting pictures by taken date instead of modification date

Created on 6 Jan 2020  ·  32Comments  ·  Source: nextcloud/photos

For travel albums or for any event, pictures modification time does not reflect the event timeline.

It happens a lot that pictures are modify (cropping, enhancements, etc.), and changing their orders does not help readability.

Could the creation date be the default info used ?

1. to develop enhancement timeline good first issue high

Most helpful comment

Could it simply be sorted by the name as a start ? With current cameras naming convention, the filename reflects the creation date order.

All 32 comments

It would be a nice enhancement.
But we currently do not store the taken date

cc @rullzer

cc @jancborchardt if it make sense

Yep, very good point – for photos it absolutely makes sense to sort by taken date, exactly for the reasons @tillwf mentioned. :)

Could it simply be sorted by the name as a start ? With current cameras naming convention, the filename reflects the creation date order.

I'd rather have modification date (like all mobile galleries work) than name

Could it simply be sorted by the name as a start ? With current cameras naming convention, the filename reflects the creation date order.

This would break down as soon as you get photos from a second camera or from friends, or the numbering of your own camera wraps – so the current way is better for now. :)

@jancborchardt You're right. However, it is not better now, because currently the order is completely random as I transfer my picture using scp. That is why I was saying "as a start". I prefer to have 2 sets of photos ordered than nothing coherent.

Guys, can't we just change this line https://github.com/nextcloud/photos/blob/c993c63a32ad3283c49852cccc249ad0d228a057/lib/Controller/AlbumsController.php#L102
to use $node->getCreationTime()?
That makes picture be displayed in a more logical order....

@frieck this suggest is about the taken date, not the creation date of the file.
So we'd need exif support

Hi @skjnldsv,
For me all photos are being displayed in an incorrect order as they all have been modified sometime.
So changing that line that I mentioned helped me to fix part of the problem, I understand that a File can have a creation date different from the photo that it represents, but that seems to be more uncommon than having a modification date and everything listed by that modification date.

@frieck not arguing with your specific issue :)
It fits some people use, but also not for others. Just reminding that this issue is about the photo taken date, not creation date.

Could the creation date be the default info used ?

Nonetheless, I just notice this line on the main post, which make this confusing :stuck_out_tongue:
@jancborchardt shall we use creation date by default instead of last modified?

@jancborchardt shall we use creation date by default instead of last modified?

Yep! :)

creation date of the file is better than the mtime, but EXIF data would ofc be best. Unfortunately, creation date (filesystem level) is also of no use if you use the NC app to sync your pictures from the phone, since all files end up with a creation date of the time of the upload :(

@skjnldsv considering the amount of discussion and also the pitfalls you mentioned in your comments, this does not seem like a good first issue?

@skjnldsv considering the amount of discussion and also the pitfalls you mentioned in your comments, this does not seem like a good first issue?

You mentioned created date, which we have. For exif taken date of course this is not a good first issue. :)
There is another issue laying around somewhere that is also similar iirc

Hi,
I would also like to sort photos by taken date, rather than last modified date, for the same reason : I have different photos, taken by different devices, covering the same event, and I would like to see them all in chronological order.
I'm new to Nextcloud, and I have a fairly limited experience with php, but I figured I could prototype some temporary function using php built-in EXIF support:

function getOriginalDate($nd) {
    $filename = $nd->getPath();
    $filebase = $nd->getName();
        if ($filebase == "." or $filebase == ".."){
                return 0;
        }
        if (exif_imagetype($filename)) {
                $exif = exif_read_data($filename, 'EXIF');
                if (is_array($exif) || is_object($exif)) {
                        foreach ($exif as $key => $value) {
                                if ($key == 'DateTimeOriginal') {
                                        return strtotime($value);
                                }
                        }
                }
        }
    return $nd->getMTime();
}

and then in photos/lib/Controller/AlbumsController.php:
'lastmod' => getOriginalDate($node)

This way, if the photo has EXIF entries I can use them, otherwise use last modified entry.
But sadly it didn't work.
So I tried to force set all modified date to EXIF taken date if available using EXIF-Tool

for i in *.JPG;
do
echo Traitement de $i
touch -t `exiftool -s -s -s -d "%Y%m%d%H%M.%S" -DateTimeOriginal $i` $i
echo `exiftool -s -s -s -d "%Y:%m:%d %H:%M:%S" -FileModifyDate $i`
echo ""
done
exit 0

But although the code ran, and the files seemed to have been modified, nothing changed when I displayed the album in Nextcloud.

I know the cleanest method would be to handle this server-side but I can't figure out what went wrong with my attempt.
Regards,
J-C

Hi @skjnldsv,
For me all photos are being displayed in an incorrect order as they all have been modified sometime.
So changing that line that I mentioned helped me to fix part of the problem, I understand that a File can have a creation date different from the photo that it represents, but that seems to be more uncommon than having a modification date and everything listed by that modification date.

Does this require a "rescan" or should it work out of the box?

But although the code ran, and the files seemed to have been modified, nothing changed when I displayed the album in Nextcloud.

@jcclerval , belief is that you'd need to run re-scan at least on that folder where photos are.

The best would be to have your approach implemented, meaning:
a) try to extract EXIF picture taken timestamp (normalize to UTC) and display either at presentation layer translated to local one or use timezone as in EXIF,
b) check if file naming convention doesn't reveal YYYY-MM-DD or something similar (trick is to small amount of files is available, i.e. what means 2020-01-01 - for most of Europeans it would be Jan 1st, but not necessarily for everyone),
c) if nothing of above gives good result, use file timestamp (last resort).

This would need to be stored somewhere in a table, probably together with other EXIF related details, like GPS, etc.
This opens nice avenue for presentation layer.

Indeed, I ran a re-scan and now it works 👍 (although it only was the original code with altered last modification date, now I'll try to check the piece of code with non-altered photos)

I think it would be useful to have an option to set cdate of photos to exif DateTimeOriginal and sort photos by cdate. In my opinion, this feature is very important to the photos app as users expect photos to always be sorted by the date they were taken.

Is anyone working on this already? @skjnldsv @jancborchardt Maybe if there's a PR started I could help.

@Zaijo hi, right now no one seems to be working on this – if you want to dig into the code that would be great! @skjnldsv @Mikescops will be able to help with any questions. :)

OK, how can we communicate about this? Do you have a chat or developer forum somewhere? I need help.

BTW, there's this application https://github.com/gino0631/nextcloud-metadata which can already extract metadata of many formats. Is there a way to use that? @Mikescops @skjnldsv ?

@Zaijo I am also interested in helping out with this one. Let me know.

I'm sorry guys but in between I found Photoprism https://docs.photoprism.org/ which I now use alongside with Nextcloud and this EXIF way for Nextcloud Photos seems to have a veeeery long path before it's usable for me.

@Zaijo , did you use some guide to install photoprism and set it up with nextcloud? This sync-option looks like it duplicates the image data (?) https://docs.photoprism.org/user-guide/settings/sync/

Let's move to e.g. Twitter with that so we don't spam this thread. https://twitter.com/zaj0

BTW, there's this application gino0631/nextcloud-metadata which can already extract metadata of many formats. Is there a way to use that? @Mikescops @skjnldsv ?

Like mentioned on this thread and others multiple time, this require metadata to be merged and shipper into nextcloud server, available through dav and have a dedicated API for other apps.
Then it would be a few lines of code for the Photos app.

Why is this still a thing?

I want to switch to Nextcloud from Google Photos, means I did a full Google Export and uploaded the around 100.000 files to Nextcloud just to figure this out.

When will you change this?

I reckon it will take some time before it is properly managed server-side. How about some partial temporary feature using PHP built-in EXIF support ? Something similar at what I have written above, but better and at the right place ?

No, it must be done right or none at all. Temporary hackish features are what got us in lots of trouble in lots of areas. And then no one maintains it, and it suddenly becomes the bottleneck for any desired changes. :confounded:

Locking this thread, nothing more productive seems to be added, you are all free to start working on this and I will help you implement it if you do. :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xf- picture xf-  ·  9Comments

Skeebopstop picture Skeebopstop  ·  9Comments

DanBenHa picture DanBenHa  ·  12Comments

iwanttobefreak picture iwanttobefreak  ·  7Comments

andrzej-r picture andrzej-r  ·  7Comments