Exif date picture taken - "quick mod" Exif date picture taken - "quick mod"
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Exif date picture taken - "quick mod"

Started by elbarneso, June 23, 2006, 08:22:49 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

elbarneso

Hello Everyone!

I thought I'd post a quick edit I put into my own Coppermine gallery for displaying and sorting on the date a picture was taken as opposed to uploaded. The approach I have taken is to load the DateTimedigitized Exif field and added it to the cpg148_pictures result set as if it was part of the sql query. I don't store the field on the cpg148_pictures table as in other mods I have seen, so I then have to do any sorting in memory as opposed to using orderby sql. I guess the tradeoff is that the mod is quicker to implement, but suffers in performance - the modified code can also be harder to follow since multiple sorting approaches are being mixed.

The changes below require changing core files, so please keep track of them to ease in future upgrades.

1. copy the attached file "tmb.inc.php" to your /include directory. This basically keeps any new functions I added off to the side and easy to edit. You can name this whatever you want, just make sure step #2 is in sync

2. add "include_once("include/tmb.inc.php");" to the bottom of your function.inc.php file - now you will have access to new functions addDatePictureTaken(), sortByDatePictureTaken(), and array_key_multi_sort()

3. change the exif and iptc "include" lines in displayImage.php to be "include_once" (for cpg1.4.8 these are displayImage.php lines 40 and 43). This will keep you from getting a duplicate definition error since I had to include these files elsewhere.

4. make sure both line 84 and 85 are uncommented in exif_php.inc.php - I may have been able to avoid this and I'm not sure the history behind this file, but like I said above, this mod is meant to be quick and dirty to get the functionality to work...


                $exifParsed[$lang_picinfo[$key]] = $val;
                $exifParsed[$key] = $val;


5. now that the supporting files are in place, let's make the big changes to functions.inc.php. get_pic_data() is the function that queries the pictures table and populates a resultset already sorted. For any "album type" we want, we need to add a new variable (calling it 'ptime' as I have seen this used elsewhere in these forums) to the rowset, add ptime to the thumbnail caption, and then re-sort based on ptime if the user clicked one of the Date +/- sort headers:

5a. add the following line right before each call to build_caption() in get_pic_data() where you want to have access to ptime:


                addDatePictureTaken($rowset);


5b. add the following to the bottom of the "build_caption" function (line 869) to allow display of the Date Taken field.


        if (in_array('ptime',$must_have)) {
                $caption .= "<span class=\"thumb_caption\">".$row['ptime'].'</span>';
        }


5b. edit the build_caption call you located in 5a to include ptime. Here would be an example:


                if ($set_caption) build_caption($rowset, array('ptime'));


5c. right before returning the $rowset, re-sort based on ptime by calling the following:


                sortByDatePictureTaken(&$rowset, $sort_code);


Some notes/limitations:

  • If you are on cpg148 and don't want to edit your functions.inc.php (steps #2 and #5 above), I have attached a version with the above edits
  • The date is crudely formatted i.e. 2006:06:01 11:22:33. Feel free to edit step 5b above with php date functions to format nicely in the caption as it will not affect the sorting.
  • My pictures were taken with Canon or were scanned pics that I used the application Exifer to add DateTimedigitized to the picture's exif data. I don't know of any problems you would have as the exif tags should be consistent, but just thought I'd mention it.

That's about it - let me know if you have any problems!

Tim
===

Paver

Brilliant!  Works nicely.  And great guide to implementing it.  I have tried it in a few places - looking forward to adding it throughout my gallery.

I like the fact that you pull the 'ptime' and add it to $rowset instead of modifying the pictures database.  Not as efficient to be sure, but a much more germane route, at least for what I want.

elbarneso

Oops - original tmb.inc.php posted was missing the reverse date sort case. Here is the updated one...

Paver

I would recommend posting the revised one in the first post, either replacing the current pack or as an additional file.  Since this is a bug replacement, I would go with the former (replacing the current pack).

By keeping the updates in the first post, it's easy for new people to see what the current mod is.  You can keep a changelog there too, if you like.  But since you probably are "done" with this mod, that's probably not necessary.

jsalbre

Great hack, but it doesn't seem to matter which I select, it always sorts ascending (oldest -> newest.)

jsalbre

It also appears that with this mod installed when I click on a thumbnail it is linked to the wrong image.

scooter32

For those that have been having problems with the wrong image showing up with this mod.
One of the things I noticed was a php error about not passing things via references as it
is deprecated or something.  I went with this assumption and modified

include/functions.inc.php around line 965 and removed the reference to passing by reference

sortByDatePictureTaken($rowset, $sort_code);

Then I modified tmb.inc.php around like 33 and changed the function to

function sortByDatePictureTaken($rowset, $sortCode)

removing the pass by reference.

This seems to have fixed the problem. 


inciteweb


Mod seems to work fine but I have the problem with wrong image displayed after click.
If I remove the "&" reference in functions and tmb files, images are not sorted by ptime...

Any idea ?

Thx

PalSys

Great mod, my wife has been asking me to do this for her for ages! I fixed the problem with the thumbs linking to the wrong images by making one quick modification to functions.inc.php:

One line 961, remove: sortByDatePictureTaken($rowset, $sort_code);

PTesting

it doesn't work with me.

Made all modifactions, removed the reference, but he is stil not sorting by TimeDgitized (but the jpg have the correct values in this exif field, so it should work, if this mod would ...).

Any ideas?

bennettsweb

Problem I've found is that it sorts the pictures on that page of thumbnails, but albums with more than one page are not sorted overall.

bennettsweb

Ok, ended up adding ptime to the picture table database then sorting by that before the pic_info function cuts the $rowset into pages.  I think that's why this mod didn't work for me -- I have many pages of thumbnails and the pid was often very different than the Exif date which I wanted to sort by. 

I wish I was organized enough to present a full mod here, but I can try to help if you're working on the same thing.

Best - ben

nasiri

is this also avalaible for 1.5.x ???

thank you for help
Nasiri Media
Web Development in Münster / Germany

http://www.nasiri.com