Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1] 2   Go Down

Author Topic: Sort by EXIF date  (Read 5197 times)

0 Members and 1 Guest are viewing this topic.

Ludger

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 23
Sort by EXIF date
« 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 .
« Last Edit: January 15, 2018, 07:09:41 pm by Ludger »
Logged

Ludger

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 23
Re: Sort by EXIF date
« Reply #1 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).
« Last Edit: January 10, 2018, 07:02:58 pm by Ludger »
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15757
Re: Sort by EXIF date
« Reply #2 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.
Logged

Ludger

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 23
Sort by EXIF date
« Reply #3 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...
Logged

Ludger

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 23
Re: Sort by EXIF date
« Reply #4 on: December 15, 2017, 03:58:32 pm »

...forgot the link...
« Last Edit: December 28, 2017, 11:06:18 pm by Ludger »
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15757
Re: Sort by EXIF date
« Reply #5 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.
Logged

ron4mac

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Posts: 1173
Re: Sort by EXIF date
« Reply #6 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 because of that.
Logged

Ludger

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 23
Re: Sort by EXIF date
« Reply #7 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...
Logged

Ludger

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 23
Re: Sort by EXIF date
« Reply #8 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...
Logged

ron4mac

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Posts: 1173
Re: Sort by EXIF date
« Reply #9 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';
Logged

Ludger

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 23
Re: Sort by EXIF date
« Reply #10 on: December 22, 2017, 10:45:40 pm »

...I have now implemented the things you were proposing:
  • The initial Generation of EXIF data is now done on many small queries via AJAX. Also, this process now runs asynchronous, meaning the user can do different things in the meantime.
  • In case PHP-EXIF is not present, the plugin chooses the internal EXIF decoder already built into the Coppermine. Though, I found this one to be not very reliable, especially with Canon-JPGs it throws a lot of exceptions. The PHP7-decoder is also not 100%, so would you like me to check for the problem?
« Last Edit: December 28, 2017, 11:06:35 pm by Ludger »
Logged

Ludger

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 23
Re: Sort by EXIF date
« Reply #11 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...
« Last Edit: December 28, 2017, 11:06:53 pm by Ludger »
Logged

Phill Luckhurst

  • Administrator
  • Coppermine addict
  • *****
  • Country: gb
  • Offline Offline
  • Gender: Male
  • Posts: 4659
    • Windsurf.me
Re: Sort by EXIF date
« Reply #12 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.
Logged
It is a mistake to think you can solve any major problems just with potatoes.

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15757
Re: Sort by EXIF date
« Reply #13 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.
Logged

Ludger

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 23
Re: Re: Sort by EXIF date
« Reply #14 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...
Logged

Ludger

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 23
Re: Re: Sort by EXIF date
« Reply #15 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:
  • Improve the upload routine to conserve the file date
  • Enable my plugin (and later cpg_exif) to read the most common metadata standards from video files
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...
Logged

Ludger

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 23
Re: Sort by EXIF date
« Reply #16 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...
Logged

ron4mac

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Posts: 1173
Re: Sort by EXIF date
« Reply #17 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));
« Last Edit: January 09, 2018, 10:32:05 pm by ron4mac »
Logged

Ludger

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 23
Re: Re: Sort by EXIF date
« Reply #18 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. 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...
Logged

ron4mac

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Posts: 1173
Re: Sort by EXIF date
« Reply #19 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).
Logged
Pages: [1] 2   Go Up
 

Page created in 0.028 seconds with 20 queries.