Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > iphoto to php based gallery in a calendar format

iphoto to php based gallery in a calendar format
Thread Tools
barbarian
Senior User
Join Date: Apr 2001
Location: Palo Alto, CA
Status: Offline
Reply With Quote
Jan 26, 2004, 10:13 AM
 
I was wondering if anyone out there has created the php code needed to turn an iphoto gallery into an online gallery.

Not just any gallery but one that is formatted as a calendar with the first photo for any particular day shown as the thumbnail.

Click on a day and you get all the photos for the day arranged by hour.

Click on any photo and you see it full sized....

Anyone know of anything like this?
     
Synotic
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jan 26, 2004, 03:52 PM
 
Originally posted by barbarian:
I was wondering if anyone out there has created the php code needed to turn an iphoto gallery into an online gallery.

Not just any gallery but one that is formatted as a calendar with the first photo for any particular day shown as the thumbnail.

Click on a day and you get all the photos for the day arranged by hour.

Click on any photo and you see it full sized....

Anyone know of anything like this?
What do you mean by "iPhoto Gallery"? Are you talking about some format it exports or just the actual database on the HD? I don't know if anything exists but this does seem like a cool idea. I might try messing around with it myself.
     
ppmax
Dedicated MacNNer
Join Date: Nov 1999
Status: Offline
Reply With Quote
Jan 26, 2004, 05:24 PM
 
Check out BetterHTMLExport. It will let you create custom layouts etc. I use it and have created my own layout using CSS, PHP, etc.
     
skalie
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status: Offline
Reply With Quote
Jan 27, 2004, 06:38 AM
 
     
barbarian  (op)
Senior User
Join Date: Apr 2001
Location: Palo Alto, CA
Status: Offline
Reply With Quote
Jan 27, 2004, 08:37 PM
 
<b>re gallery and betterhtmlexport</b>

Both are fine programs but they are really geared towards displaying albums as photo galleries.

I'm talking about something similar, but one that functions as a photocalendar or photoblog.

<b>What do you mean by "iPhoto Gallery"? Are you talking about some format it exports or just the actual database on the HD? I don't know if anything exists but this does seem like a cool idea. I might try messing around with it myself.</b>

Again the idea is to have php code use the existing iphoto format (it's already sorted and organized by date) to create a calendar.

You would be able to see a calendar with thumbnails on each day on which you took photos.

Clicking on a day would show thumbs for all the photos from that day organized by time.

Clicking on a photo would see the full sized photo.

In my perfect world I could have the option to browse the library either locally (using the local iphoto library) or on the web (where the library would simply be copied to a server along with the php code).

In fact in a perfect world the code could handle any collection of photos organized using the iphoto method (folders for years, folders for months, time of photos = creation date of photo).

I would expect that the program would have to generate thumbs as the iphoto thumbs are too large to be web friendly.
     
skalie
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status: Offline
Reply With Quote
Jan 28, 2004, 04:39 AM
 
http://www.zwily.com/iphoto/index.xsl

Also check out the support forum for gallery, this thread for example.

If what you want hasn't been already put together I'm sure there would only be a few tweaks needed to the source code that they provide.
     
barbarian  (op)
Senior User
Join Date: Apr 2001
Location: Palo Alto, CA
Status: Offline
Reply With Quote
Feb 6, 2004, 01:01 AM
 
thanks for the links... none of those is exactly what I am looking for, but some might be modifiable...

I basically want an app that allows me to load daily images to ultimately produce a little calendar that looks like the one below:



By clicking on one of those days, I want see all the photos for that day (thumbnails laid out in a chronological grid separated by hour markers).

Something like this but organized by time: http://blackholemedia.com/aaron/log/photo.php?id=78

The key thing is making it like a blog... ie allowing flexible uploads and live calendaring...
     
SAgent0068
Fresh-Faced Recruit
Join Date: Nov 2003
Location: Ithaca, NY
Status: Offline
Reply With Quote
Feb 14, 2004, 08:52 PM
 
Not quite the perfect match to what you describe, but there's myPhoto (see my signature)
myPhoto: all you have to do is plug in your digital camera, import your photos as you normally would into iPhoto, organize them, add whatever captions you want, and voila! Your photos are on your web page! And what did you have to do to put them there? Simply install myPhoto.
     
Synotic
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Feb 15, 2004, 02:30 AM
 
SAgent0068, or anyone else who might know... how do you get the creation dates of the photos in iPhoto? I am seeing values like '67046674.000000' in 'DateAsTimerValue' in iPhoto's DB. What format is this? I'm just messing around with this in PHP and got stuck here.
     
SAgent0068
Fresh-Faced Recruit
Join Date: Nov 2003
Location: Ithaca, NY
Status: Offline
Reply With Quote
Feb 15, 2004, 09:28 AM
 
edit: I'm close to having it, but for some days, I'm about one day off (i.e. xmas on 12/26)
( Last edited by SAgent0068; Feb 15, 2004 at 10:29 AM. )
myPhoto: all you have to do is plug in your digital camera, import your photos as you normally would into iPhoto, organize them, add whatever captions you want, and voila! Your photos are on your web page! And what did you have to do to put them there? Simply install myPhoto.
     
Synotic
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Feb 16, 2004, 03:32 PM
 
I mentioned I was messing around with this and I think I got something working pretty well so far Currently what it does is... reads the iPhoto XML database... grabs the name of every single photo and puts it into a convenient array. Then I loop through the array of names and add a creation date... extracted from the location of the file. So if the file is in "2004/03/image.jpg" I can take that and make a rough date. Then I sort my array based on the date and then I go through and make the calendar itself. I'm still messing around with it but if you want to try it yourself... make one folder for all of the associated files such as "iphotocalendar". In that folder make a main PHP file called something like "index.php"... inside put:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <title>iPhoto Calendar</title> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <style type="text/css"> body { margin: 7px; padding: 0; font: 10px "Lucida Grande" } #title { width: 569px; margin: 0 0 7px; text-align: center; font-weight: bold } #calendar { width: 567px; height: 305px; border: solid 1px black; border-width: 1px 0 0 1px; background: black } #calendar div { width: 80px; height: 60px; border: solid 1px black; border-width: 0 1px 1px 0; background: white; text-align: right; float: left } #calendar div b { padding: 2px 3px 0 0; display: block } </style> </head> <body> <?php $photosArray = retrieveDB(); displayCalendar("2003", "12", $photosArray); function displayCalendar($year, $month, $photos) { echo ' <div id="title">'.date("F",mktime(0,0,0,intval($month),1,intval($year))).' '.$year.'</div>'; echo ' <div id="calendar">'."\n"; $displayedMonth = $photos[$year][$month]; $monthStartDay = intval(date("w",mktime(0,0,0,intval($month),1,intval($year)))); for ($i=1; $i<=$monthStartDay; $i++) { echo " <div></div>\n"; } $daysInMonth = date("j",mktime(0,0,0,$month+1,0, $year)); for ($i=1; $i<=$daysInMonth; $i++) { if ($i<10) $day = '0'.strval($i); if ($i>9) $day = strval($i); if (array_key_exists($day,$displayedMonth)) { // echo ' <div><img width="80" height="60" align="top" src="file:///'.$displayedMonth[$day][0].'" /></div>'."\n"; echo ' <div><img width="80" height="60" align="top" src="putanimagehere.jpg" /></div>'."\n"; } else { echo " <div><b>$day</b></div>\n"; } } for ($i=1; $i<=(35-($monthStartDay+$daysInMonth)); $i++) { echo " <div></div>\n"; } } function retrieveDB() { include 'clsParseXML.php'; $xmlparse = &new ParseXML; $xml = $xmlparse->GetXMLTree("AlbumData.xml"); $allPhotos = $xml['PLIST'][0]['DICT'][0][DICT][0][DICT]; foreach($allPhotos as $i) { $photoLocation = $i['STRING'][1]['VALUE']; $exDate = explode("/", $photoLocation); $photoDate = mktime(0, 0, 0, $exDate[6], $exDate[7], $exDate[5]); $photosWithDates[$photoLocation] = $photoDate; } asort($photosWithDates); foreach($photosWithDates as $key => $value) { $photosArray[date("Y", $value)][date("m", $value)][date("d", $value)][] = $key; } return $photosArray; } ?> </div> </body> </html>
Then make another PHP file in the same folder called "clsParseXML.php" without the quotes. Inside, put:

Code:
<?php /* XML Parser Class by Eric Rosebrock http://www.phpfreaks.com Class originated from: [email protected] AT: http://www.devdump.com/phpxml.php Usage: <?php include 'clsParseXML.php'; $xmlparse = &new ParseXML; $xml = $xmlparse->GetXMLTree('/path/to/xmlfile.xml'); echo "<pre>"; print_r($xml); echo "</pre>"; ?> The path to the XML file may be a local file or a URL. Returns the elements of the XML file into an array with it's subelements as keys and subarrays. */ class ParseXML{ function GetChildren($vals, &$i) { $children = array(); // Contains node data if (isset($vals[$i]['value'])){ $children['VALUE'] = $vals[$i]['value']; } while (++$i < count($vals)){ switch ($vals[$i]['type']){ case 'cdata': if (isset($children['VALUE'])){ $children['VALUE'] .= $vals[$i]['value']; } else { $children['VALUE'] = $vals[$i]['value']; } break; case 'complete': if (isset($vals[$i]['attributes'])) { $children[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes']; $index = count($children[$vals[$i]['tag']])-1; if (isset($vals[$i]['value'])){ $children[$vals[$i]['tag']][$index]['VALUE'] = $vals[$i]['value']; } else { $children[$vals[$i]['tag']][$index]['VALUE'] = ''; } } else { if (isset($vals[$i]['value'])){ $children[$vals[$i]['tag']][]['VALUE'] = $vals[$i]['value']; } else { $children[$vals[$i]['tag']][]['VALUE'] = ''; } } break; case 'open': if (isset($vals[$i]['attributes'])) { $children[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes']; $index = count($children[$vals[$i]['tag']])-1; $children[$vals[$i]['tag']][$index] = array_merge($children[$vals[$i]['tag']][$index],$this->GetChildren($vals, $i)); } else { $children[$vals[$i]['tag']][] = $this->GetChildren($vals, $i); } break; case 'close': return $children; } } } function GetXMLTree($xmlloc){ if (file_exists($xmlloc)){ $data = implode('', file($xmlloc)); } else { $fp = fopen($xmlloc,'r'); while(!feof($fp)){ $data = $data . fread($fp, 1024); } fclose($fp); } $parser = xml_parser_create('ISO-8859-1'); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, $data, $vals, $index); xml_parser_free($parser); $tree = array(); $i = 0; if (isset($vals[$i]['attributes'])) { $tree[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes']; $index = count($tree[$vals[$i]['tag']])-1; $tree[$vals[$i]['tag']][$index] = array_merge($tree[$vals[$i]['tag']][$index], $this->GetChildren($vals, $i)); } else { $tree[$vals[$i]['tag']][] = $this->GetChildren($vals, $i); } return $tree; } }
This is just a useful class I used to turn the XML file into an array which I can then manipulate. Finally, copy over your iPhoto DB (~/Users/Pictures/iPhoto Library/AlbumData.xml) into the same folder as all the other files. At this point you should be able to run "index.php" from your browser.

Notes:
In index.php, do a search for "putanimagehere". Put a link to any image you want... size doesn't matter it'll resize for you. If you want to, instead, show an actual image from that day, then uncomment the line above it, and comment the "putanimagehere" line. Keep in mind that your shrinking generally very large images... so this can slow your browser down.

Mainly out of laziness... I didn't write any code yet to make sure displayCalendar() works with dates on which no photos were taken. Therefore make sure you give it a date that you know you took photos. This is referring to the "displayCalendar("2003", "12", $photosArray);" line. I'll try and fix that up later...

The array is sorted by date... but I can't figure out a simple way to sort all of the photos taken on each day. Is there a simple way to do this? Or do I just have to loop through each year... and then each month... and then each day... and individually sort each day?

Big question: php.net claims that gd is built into PHP 4.3 and above... whenever I try and use any image processing feature it claims the function is undefined. Does anyone know what files I have to change, libraries I have to install etc... to get this working? Without gd I won't be able to make any thumbnails which are pretty essential. Also gd lets me read EXIF data... this means that I can read the exact time a photo was taken by extracting the data from the image.

OK, I hope this works for you... it's pretty rough around the edges but should give you a rough idea of what I'm trying to do

P.S. If the horizontal length of the code is annoying anyone I can host the files and just link them.
     
Synotic
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Feb 16, 2004, 03:46 PM
 
One thing I just noticed... I mentioned that it would screw up if you fed it a date that didn't exist... It'll also screw up if you enter a non 2 digit number... for now the fix is pretty simple... if you want to put in May 2003 then just put in "05" instead of "5".
     
Simon Mundy
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Feb 17, 2004, 01:19 AM
 
Originally posted by Synotic:
One thing I just noticed... I mentioned that it would screw up if you fed it a date that didn't exist... It'll also screw up if you enter a non 2 digit number... for now the fix is pretty simple... if you want to put in May 2003 then just put in "05" instead of "5".
I haven't tried this yet... but had a quick thought about extracting the date from the path:-

$photoDate = strtotime(preg_replace('!.*/(\d{4})(/\d{1,2})(/\d{1,2})?/.*!','\1\2\3',$photoLocation));

If I haven't screwed up the regexp, then this should turn a string like '/Users/smundy/Pictures/iPhoto Library/2003/12/17/IMG_0049.JPG' into a string that reads '2003/12/17' and then turns it into a timestamp with the handy 'strtotime' function. This will be more robust, as the strtotime function is very forgiving in the way it interprets time strings. It should also work even if the string is '/Users/smundy/Pictures/iPhoto Library/2003/12/IMG_0049.JPG' - it would turn the time into 2003/12 which would default to 1st December 2003.

Helpful?
Computer thez nohhh...
     
SAgent0068
Fresh-Faced Recruit
Join Date: Nov 2003
Location: Ithaca, NY
Status: Offline
Reply With Quote
Feb 18, 2004, 11:56 AM
 
While parsing the directory structure is an available option, it neglects the timestamps of the photos. I am working to obtain that much (without resorting to the EXIF data since not everybody cares to upgrade the default install of PHP) and almost have it (it's occasionally one day off).

Also, Synotic, maybe you should check out myPhoto? Might save you some trouble...
myPhoto: all you have to do is plug in your digital camera, import your photos as you normally would into iPhoto, organize them, add whatever captions you want, and voila! Your photos are on your web page! And what did you have to do to put them there? Simply install myPhoto.
     
barbarian  (op)
Senior User
Join Date: Apr 2001
Location: Palo Alto, CA
Status: Offline
Reply With Quote
Feb 18, 2004, 01:17 PM
 
Hey synotic that's a great start. I can now have a very clear idea of what needs to be done! Next week I'm going to have a nice block of time to play with this. I want to add some css so that you can control the look of the calendar with css.

Re the date, which is more accurate directory structure, timestamp, or exif? Which one is correct if the user manually changes a photo date (I'm out of town and away from my mac so I can't check right now)...
     
Synotic
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Feb 18, 2004, 05:44 PM
 
Originally posted by SAgent0068:
While parsing the directory structure is an available option, it neglects the timestamps of the photos. I am working to obtain that much (without resorting to the EXIF data since not everybody cares to upgrade the default install of PHP) and almost have it (it's occasionally one day off).

Also, Synotic, maybe you should check out myPhoto? Might save you some trouble...
To adapt it or just for help? I actually did look through it and it's pretty interesting... are you actually creating your own thumbnails without any outside functions? I guess I'll have to check that out... Right now I used an example I found off the php.net docs and it's incredibly slow...

This probably isn't the right thread but some concerns I had with myphoto was that to override the fact that the Pictures is unaccessible by the script you had to transfer the actual photo library to myphoto's directory and then create an alias in the original location... My particular script claimed that an image in the library didn't exist when it checked for an image in the library... I uninstalled myphoto and it finally worked. And speaking of uninstalling... why do you have to shut down my web server? Also is my httpd.conf being completely replaced or are you just modifying certain lines? What changes do you need to make to the httpd.conf anyways? Just some things that caught my attention...

Originally posted by barbarian:
Hey synotic that's a great start. I can now have a very clear idea of what needs to be done! Next week I'm going to have a nice block of time to play with this. I want to add some css so that you can control the look of the calendar with css.

Re the date, which is more accurate directory structure, timestamp, or exif? Which one is correct if the user manually changes a photo date (I'm out of town and away from my mac so I can't check right now)...
EXIF is probably the most accurate but probably slower than just checking the database. If you're interested I finally got GD working after updating using a PHP package install. The script can currently do what it originally did but now actually takes the image for the particular day, makes a thumb and uses it.

Re css... if you noticed, it's currently using that completely to make the calendar as opposed to using a table which would be annoying to deal with codewise. So yeah, you'll be able to add any other css you want.
     
SAgent0068
Fresh-Faced Recruit
Join Date: Nov 2003
Location: Ithaca, NY
Status: Offline
Reply With Quote
Feb 18, 2004, 10:07 PM
 
Originally posted by Synotic:
To adapt it or just for help? I actually did look through it and it's pretty interesting... are you actually creating your own thumbnails without any outside functions? I guess I'll have to check that out... Right now I used an example I found off the php.net docs and it's incredibly slow...
I just figured I'd point it out to save you the trouble of having to reinvent the wheel, so to speak. As for creating the thumbnails, I only create thumbnails when the user opts to have the images scaled down.

This probably isn't the right thread but some concerns I had with myphoto was that to override the fact that the Pictures is unaccessible by the script you had to transfer the actual photo library to myphoto's directory and then create an alias in the original location...
There's the option of symlinks for those who are concerned by this--I would do it by default, but for some reason, I haven't had very consistent results with everybody, so this seems easier and more effective.

My particular script claimed that an image in the library didn't exist when it checked for an image in the library... I uninstalled myphoto and it finally worked. And speaking of uninstalling... why do you have to shut down my web server? Also is my httpd.conf being completely replaced or are you just modifying certain lines? What changes do you need to make to the httpd.conf anyways? Just some things that caught my attention...
Sorry about shutting down the web server--I just assumed that most users never ran a web server before (which is generally true, believe it or not). As for your config file, the installer backs up your httpd.conf before doing anything to it when your first install myPhoto. Uninstalling restores that back up.

EXIF is probably the most accurate but probably slower than just checking the database. If you're interested I finally got GD working after updating using a PHP package install. The script can currently do what it originally did but now actually takes the image for the particular day, makes a thumb and uses it.
EXIF is agreeably the most accurate but I avoid it only because some users don't want to upgrade their PHP in any way and so they don't have any of the EXIF functionality available to them. It would certainly make life easier though.

If you'd care to discuss this any further, we should probably take it out of this thread. I can be reached at [email protected].
myPhoto: all you have to do is plug in your digital camera, import your photos as you normally would into iPhoto, organize them, add whatever captions you want, and voila! Your photos are on your web page! And what did you have to do to put them there? Simply install myPhoto.
     
macgyvr64
Grizzled Veteran
Join Date: Jun 2001
Status: Offline
Reply With Quote
Feb 18, 2004, 10:43 PM
 
This thread is extremely useful, especially the iPhoto XML parsing and GD. Was it a problem on your end with PHP that stopped GD from working? (Read: Should it working on my system with php 4.3.4 install?). Thanks!
     
Synotic
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Feb 19, 2004, 08:13 AM
 
Originally posted by macgyvr64:
This thread is extremely useful, especially the iPhoto XML parsing and GD. Was it a problem on your end with PHP that stopped GD from working? (Read: Should it working on my system with php 4.3.4 install?). Thanks!
Unfortunately Apple chose to install PHP on Mac OS X without gd enabled. Therefore I had to install entropy's packaged version.
     
macgyvr64
Grizzled Veteran
Join Date: Jun 2001
Status: Offline
Reply With Quote
Feb 19, 2004, 11:08 AM
 
Hehe, I also use his ImageMagick package, but might not now that I saw how easy NetPBM is to install..
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 01:54 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,