forum.coppermine-gallery.net

Support => cpg1.6 plugins => cpg1.6.x Support => cpg1.6 plugin contributions => Topic started by: Ludger on December 15, 2017, 01:28:34 am

Title: Sort by EXIF date
Post by: Ludger on December 15, 2017, 01:28:34 am
I hope this is the right place, so here we go:
Good evening,
I am new to this forum and have just recently moved my private picture and movie gallery to a Coppermine-based site. I like the software very much with one exception: I painfully missed the option of sorting the album thumbnails by the original date from EXIF data. And since I am used to making the things I miss myself, I started making a new plugin for exactly this purpose. Now this thing is basically done, I am still testing...
To do what it is supposed to do, my plugin depends on 2 CPGPluginAPI-Lines that I added to functions.inc.php. Would it be possible to add these two "plugs" to future releases of Coopermine 1.5 and 1.6? My plugin works with these two versions.
Best regards from Aachen, Germany
Ludger
PS: I have opend a smal part of my site on http://bergdriesch22.de . The universal registration password is himbeereis123 .
Title: Re: Sort by EXIF date
Post by: Ludger on December 15, 2017, 01:37:43 am
...these are the modified functions.inc.php . In the 1.5 version I added lines 1367 and 2155, in 1.6 I added the same lines at 1415 and 2177.
PS: I updated the patching according to what Ron did (see below).
Title: Re: Sort by EXIF date
Post by: Αndré on December 15, 2017, 12:16:17 pm
Some remarks. The check for $main_version is probably not needed, if you use the database wrapper functions, e.g. cpg_db_num_rows instead of mysql_num_rows.

I haven't found any code to insert the EXIF timestamp for files that will be added after plugin installation.

It seems you insert all EXIF timestamps during plugin installation. This will probably fail on large galleries with a comparatively small timeout value. You should better do this in a loop and add just (let's say) 100 items a time, like we do in the admin tools. Maybe a separate button to update (missing) EXIF timestamps will to the trick.

The plugin hooks themselves looks valid.
Title: Sort by EXIF date
Post by: Ludger on December 15, 2017, 03:57:31 pm
The check for $main_version is probably not needed, if you use the database wrapper functions, e.g. cpg_db_num_rows instead of mysql_num_rows.
You are right. This saves me about 30 lines of code.

Quote
I haven't found any code to insert the EXIF timestamp for files that will be added after plugin installation.
My hook into CPGPluginAPI::action('add_file_data_success', $CURRENT_PIC_DATA) got lost somehow. Now it is in again.

Quote
It seems you insert all EXIF timestamps during plugin installation. This will probably fail on large galleries with a comparatively small timeout value. You should better do this in a loop and add just (let's say) 100 items a time, like we do in the admin tools.
The updates already take place in a loop as one query execution per loop. Here is the loop:

   while ($picture = single_picture($result2)) {
      $result = load_exif($picture);   
   };

And here is the function called:

function load_exif($picture) {
   global $CONFIG;
   $exifdata = exif_read_data($CONFIG['fullpath'].$picture['filepath'].$picture['filename']);
   if (isset($exifdata['DateTimeOriginal'])) {
         $datum = $exifdata['DateTimeOriginal'];
         $isexif = 1;
      } else {
         $datum = date('Y-m-d H:i:s:', filectime($CONFIG['fullpath'].$picture['filepath'].$picture['filename']));
         $isexif = 0;
      };
   $result = cpg_db_query("update {$CONFIG['TABLE_PICTURES']} set sbe_exif_date='{$datum}', sbe_source_is_exif='{$isexif}' where pid = {$picture['pid']}");
   return $result;
}

Just putting another big loop around my small one does not make sense for me, does it?

Quote
Maybe a separate button to update (missing) EXIF timestamps will to the trick.
I think, this is not needed, because EXIF is added after Upload. But still a button to re-EXIF (for example once you have exchanged some pictures) would be useful. I am just wondering about the right place for that button. I attached an updated version of the plugin...
Title: Re: Sort by EXIF date
Post by: Ludger on December 15, 2017, 03:58:32 pm
...forgot the link...
Title: Re: Sort by EXIF date
Post by: Αndré on December 15, 2017, 04:12:21 pm
The updates already take place in a loop as one query execution per loop. Here is the loop:

   while ($picture = single_picture($result2)) {
      $result = load_exif($picture);   
   };

Maybe "loop" was the wrong word. What I meant is something like we do in the admin tools when resizing pictures. It processes a couple of images, then reload the page and then process the next couple of images. Without a reload of the page (or AJAX) you still may exceed the PHP maximum execution time.
Title: Re: Sort by EXIF date
Post by: ron4mac on December 15, 2017, 05:00:27 pm
Also:  you shouldn't rely on exif_read_data() being available. See the change I had to make here (https://github.com/coppermine-gallery/cpg1.6.x/commit/083e27f0d1511c3428dce8f001a55a2fb3c88d8c) because of that.
Title: Re: Sort by EXIF date
Post by: Ludger on December 16, 2017, 11:04:38 am
André: I understand the problem. Had that timeout once on my real-life system. I am heading for launching a JavaScript, that starts a couple of Ajax-Worker-Spawns for the database. It will be interesting to see, if I can manage that through the plugin backdoors...
Title: Re: Sort by EXIF date
Post by: Ludger on December 16, 2017, 11:07:49 am
Ron: I understand that there is already an EXIF reader in the software. Is that reachable for plugins? I would like to use it as fallback...
Title: Re: Sort by EXIF date
Post by: ron4mac on December 16, 2017, 02:16:05 pm
Ron: I understand that there is already an EXIF reader in the software. Is that reachable for plugins? I would like to use it as fallback...
Yes, you would do that similar to how it is done in the link above.
For a plugin, just add include_once 'include/exif.php';
Title: Re: Sort by EXIF date
Post by: Ludger on December 22, 2017, 10:45:40 pm
...I have now implemented the things you were proposing:
Title: Re: Sort by EXIF date
Post by: Ludger on December 26, 2017, 09:10:23 pm
...fixed one problem with reading the file date in case there is no exif on certain Linux-Server...
Title: Re: Sort by EXIF date
Post by: Phill Luckhurst on December 27, 2017, 12:42:41 am
Seems to be coming on nicely. I have changed your membership to Contributor so you can add updated versions to your first post.
Title: Re: Sort by EXIF date
Post by: Αndré on December 27, 2017, 03:13:36 pm
would you like me to check for the problem?

Any suggestions for improved cpg functions are welcome 8) In an ideal world we would just call cpg_exif (or whatever is the current or future name) and the function chooses itself the best way to retrieve the EXIF data according to available PHP EXIF functions.
Title: Re: Re: Sort by EXIF date
Post by: Ludger on December 28, 2017, 10:17:35 am
Seems to be coming on nicely. I have changed your membership to Contributor so you can add updated versions to your first post.
Thank you, Phill...
Title: Re: Re: Sort by EXIF date
Post by: Ludger on December 28, 2017, 10:28:58 am
In an ideal world we would just call cpg_exif (or whatever is the current or future name) and the function chooses itself the best way to retrieve the EXIF data according to available PHP EXIF functions.
This sounds very good, lets go for it! I will look into this next year...
For now I am not 100% happy with my sort_by_exif-plugin because my videos (.mp4) still get sorted by the file date. And the file date ist reset by the upload routine of coppermine. If I do batch-upload using sftp (not ftp) everything is OK. From my point of view there are two options to fix this:
I think the second is better, because safer. Also, it would be helpful to visualize the origin of the sorting date of the image in the thumbnail list, maybe by a green, yellow or red LED-type indicator... Later I would like to add some metadata edit functionality to my plugin to enable easy fixing of problems...
Title: Re: Sort by EXIF date
Post by: Ludger on January 09, 2018, 03:00:46 pm
This thing is gaining shape and starting to get useful:

This Plugin now contains necessary additions for organizing the gallery by metadata:
- An option to sort the thumbnail list of an album by original date and time (from EXIF) is added.
- In admin mode the thumbnail list indicates the status of EXIF date: Green -> OK, Yellow -> not available.
- Also the metadata timestamp ist indicated in that list.
- For videos (MP4 only) the quicktime-metadata ist used.
Right now, the Plugin still needs two lines added in functions.inc.php for 2 new plugin-hooks.
Please see the second posting in this thread...
Title: Re: Sort by EXIF date
Post by: ron4mac on January 09, 2018, 03:42:48 pm
I will add the hooks to CPG 1.6, somewhat modified as to name and return code.

Code: [Select]
$sort_array = CPGPluginAPI::filter('thumb_get_pic_data_sortarray', $sort_array);as:
Code: [Select]
$sort_array = CPGPluginAPI::filter('pic_data_sort_array', $sort_array);and:
Code: [Select]
$sort_array = CPGPluginAPI::filter('thumb_get_pic_pos_sortarray', array($sort_array, $pid))[0];as:
Code: [Select]
$sort_array = CPGPluginAPI::filter('pic_pos_sort_array', array($sort_array, $pid));For this second one, there is no reason for you to return an array.
[edit]
Oops .. my error .. second one does need to be returned as a bundled array.
Implementing as:
Code: [Select]
list($sort_array) = CPGPluginAPI::filter('pic_pos_sort_array', array($sort_array, $pid));
Title: Re: Re: Sort by EXIF date
Post by: Ludger on January 10, 2018, 03:29:32 pm
Implementing as:
Code: [Select]
list($sort_array) = CPGPluginAPI::filter('pic_pos_sort_array', array($sort_array, $pid));
Ups, I had to look up the list command in my PHP documentation: http://php.net/manual/en/function.list.php (http://php.net/manual/en/function.list.php). This looks like we will run into problems with PHP 5, because the reading sequence there is different... I did not test that, but anyway, my hook-handler in the plugin does require both parameters (the array and the photo id) but does not change the id. So it is not necassary to return both:
Code: [Select]
$sort_array = CPGPluginAPI::filter('pic_pos_sort_array', array($sort_array, $pid));would do the trick if I change the return of the plugin routine...
Title: Re: Sort by EXIF date
Post by: ron4mac on January 10, 2018, 05:05:26 pm
Plugin filters need to return a result in the same form as variables passed to it. It is passed to other filters of the same type and must continue to be in the same form. (something I initially forgot  ;) )
So your plugin needs to return an array of the sort_array and pid (as you were doing).
Title: Re: Sort by EXIF date
Post by: Ludger on January 10, 2018, 06:54:15 pm
...understood. Just uploaded version 1.5 of the plugin that works with the latest 1.6 Coppermine without any patching needed.
I found it surprising that the plugin still works with PHP 5.
Users of Coppermine 1.5 will still have to patch the functions.inc.php...
Title: Re: Sort by EXIF date
Post by: Ludger on January 15, 2018, 07:12:53 pm
...version 1.6 can edit picture and movie metadata from the files: QT from MP4 and EXIF from JPG....