forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Miscellaneous => Topic started by: elbarneso on June 23, 2006, 08:22:49 pm

Title: Exif date picture taken - "quick mod"
Post by: elbarneso on June 23, 2006, 08:22:49 pm
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...

Code: [Select]
                $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:

Code: [Select]
                addDatePictureTaken($rowset);

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

Code: [Select]
        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:

Code: [Select]
                if ($set_caption) build_caption($rowset, array('ptime'));

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

Code: [Select]
                sortByDatePictureTaken(&$rowset, $sort_code);

Some notes/limitations:

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

Tim
===
Title: Re: Exif date picture taken - "quick mod"
Post by: Paver on June 23, 2006, 09:01:33 pm
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.
Title: Re: Exif date picture taken - "quick mod"
Post by: elbarneso on June 24, 2006, 12:45:49 am
Oops - original tmb.inc.php posted was missing the reverse date sort case. Here is the updated one...
Title: Re: Exif date picture taken - "quick mod"
Post by: Paver on June 24, 2006, 03:14:29 am
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.
Title: Re: Exif date picture taken - "quick mod"
Post by: jsalbre on June 29, 2006, 05:38:49 am
Great hack, but it doesn't seem to matter which I select, it always sorts ascending (oldest -> newest.)
Title: Re: Exif date picture taken - "quick mod"
Post by: jsalbre on June 30, 2006, 12:35:50 am
It also appears that with this mod installed when I click on a thumbnail it is linked to the wrong image.
Title: Re: Exif date picture taken - "quick mod"
Post by: scooter32 on August 01, 2006, 11:45:02 pm
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. 

Title: Re: Exif date picture taken - "quick mod"
Post by: inciteweb on October 18, 2006, 12:18:51 pm

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
Title: Re: Exif date picture taken - "quick mod"
Post by: PalSys on November 02, 2006, 12:07:28 am
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);
Title: Re: Exif date picture taken - "quick mod"
Post by: PTesting on November 19, 2006, 08:00:54 pm
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?
Title: Re: Exif date picture taken - "quick mod"
Post by: bennettsweb on December 21, 2006, 06:34:22 am
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.
Title: Re: Exif date picture taken - "quick mod"
Post by: bennettsweb on December 22, 2006, 02:20:09 am
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
Title: Re: Exif date picture taken - "quick mod"
Post by: nasiri on January 14, 2011, 02:22:31 am
is this also avalaible for 1.5.x ???

thank you for help