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]   Go Down

Author Topic: Exif date picture taken - "quick mod"  (Read 18703 times)

0 Members and 1 Guest are viewing this topic.

elbarneso

  • Coppermine newbie
  • Offline Offline
  • Posts: 2
Exif date picture taken - "quick mod"
« 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:
  • 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
===
« Last Edit: June 23, 2006, 09:02:11 pm by Paver »
Logged

Paver

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 1609
  • Paul V.
Re: Exif date picture taken - "quick mod"
« Reply #1 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.
Logged

elbarneso

  • Coppermine newbie
  • Offline Offline
  • Posts: 2
Re: Exif date picture taken - "quick mod"
« Reply #2 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...
Logged

Paver

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 1609
  • Paul V.
Re: Exif date picture taken - "quick mod"
« Reply #3 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.
Logged

jsalbre

  • Coppermine newbie
  • Offline Offline
  • Posts: 2
Re: Exif date picture taken - "quick mod"
« Reply #4 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.)
Logged

jsalbre

  • Coppermine newbie
  • Offline Offline
  • Posts: 2
Re: Exif date picture taken - "quick mod"
« Reply #5 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.
Logged

scooter32

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: Exif date picture taken - "quick mod"
« Reply #6 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. 

Logged

inciteweb

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: Exif date picture taken - "quick mod"
« Reply #7 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
Logged

PalSys

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: Exif date picture taken - "quick mod"
« Reply #8 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);
Logged

PTesting

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: Exif date picture taken - "quick mod"
« Reply #9 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?
Logged

bennettsweb

  • Coppermine newbie
  • Offline Offline
  • Posts: 7
Re: Exif date picture taken - "quick mod"
« Reply #10 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.
Logged

bennettsweb

  • Coppermine newbie
  • Offline Offline
  • Posts: 7
Re: Exif date picture taken - "quick mod"
« Reply #11 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
Logged

nasiri

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 36
    • Nasiri Web Media Development
Re: Exif date picture taken - "quick mod"
« Reply #12 on: January 14, 2011, 02:22:31 am »

is this also avalaible for 1.5.x ???

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

http://www.nasiri.com
Pages: [1]   Go Up
 

Page created in 0.021 seconds with 19 queries.