***Updated 3-18-2008***
More recent information at http://www.selfcontained.us/gallery/.
**********************
Well, this all started when Apple came out with iLife 08, and I had to go get it. After seeing their new .mac gallery I was pretty blown away with how nice of an interface it had. It made me wish I could use that instead of my Picasa gallery that I’ve been using for awhile now. Since I’m a relatively cheap person, I couldn’t justify paying for a .mac account when I had almost the same thing with Picasa for free.
After some looking around, I came across Picasa’s API. Thanks Google! With that, I had my weekend plans. I started putting something together that would just let me put my own face on a view-only gallery of my Picasa photos. After a few hours I had something I was happy with for a start.
Its still pretty basic. It pulls in albums, then you can view photos in that album, and the slideshow too. I’m using the Zend Gdata classes to parse to atom response from Google. I’m also building on top of Adroit, which right now isn’t buying me much, but will once I set up the gallery to utilize some sweet ajax. The Zend Gdata classes don’t have any concrete classes for handling the Picasa API yet, but they are working on it. I wrapped up their usage in my own PicasaImageLoader class that just pulls out the data I wanted from the Gdata feed that gets passed through their classes. I may come up with a different alternative to the Zend Gdata classes, but I wasn’t able to use the SimpleXML classes in PHP with and maintain the google specific atom tags (“gData:media”). If anyone knows easier methods of parsing an atom feed like the ones provided in this situation I’d love to hear.
This is one of the things I love about Google, giving you access to your data to do what you want with. This is what the web is about, and it sure makes their services more flexible. Checkout out my custom Picasa gallery.

41 Comments
Nice! Any way you would share the code etc you have created for the picasa interface?
Sure thing, I’ll work on making that available.
Hello,
can you send me the code of the page http://gallery.selfcontained.us/loadphoto/large.jpg?
Because i’m trying to grab using PHP a large version of the images that are on my Picasa Web Album but my scripts don’t work!
Thank you,
Greg
Sorry for the delay in this, but I’ve been wanting to make the whole gallery project source available for download. I’ll have it available for download tonight, and will post a link here.
For now, this is basically what I do in that call that loads the large version. I have that url, “loadphoto/large.jpg” routed to a particular action that does the following code (note that I pass the picasa url to that photo as a url parameter to the action called “src”. $requestData is simply an array that holds the parameters passed in from GET/POST values)
[code]]czoxNTk6XCINCiRpbWFnZSA9IGltYWdlY3JlYXRlZnJvbWpwZWcoJHJlcXVlc3REYXRhW1wnc3JjXCddLlwnP2ltZ21heD04MDBcJyk7DQpoe1smKiZdfWVhZGVyKFwnQ29udGVudC10eXBlOiBpbWFnZS9qcGVnXCcpOw0KaW1hZ2VqcGVnKCRpbWFnZSwgbnVsbCwgMTAwKTsNCmltYWdlZGVzdHtbJiomXX1yb3koJGltYWdlKTsNClwiO3tbJiomXX0=[[/code]
This will output the image, streamed from google, and act as if you are fetching that image from your own server. I could simply pass the photo id as a parameter instead of the full url, but that would require an extra lookup from google to get that photo url. Not a huge issue, but its another option.
Just a quick update, I’ve posted the gallery code for download, along with installation instructions at the following url:
http://adroit.selfcontained.us/tutorials/gallery/
This is really awesome but I’m not a coder. A layman’s tutorial would be helpful.
I agree about a layman’s guide, that would be great. Would it be possible to use this with Google Page Creator?
Thanks!
The gallery files you can download are really targeted as an Adroit (php framework) project. If there is enough inteterst, I could look at creating an install script that simplified the process a bit, so you wouldn’t have to manually edit the configuration files listed in the walkthrough. Unfortunately this gallery relies on specific configuration, and I don’t see an easy way to plug it in to Google Page Creator.
Thanks for the code! Got my album almost working at
http://www.stigin.net/gallery/webroot/
This opens the main albums index page but I still have some error in my path configurations since the actual albums or pictures don’t open. Suggestions appreciated.
Looks like maybe your .htaccess file isn’t setup correctly, as the individual album urls aren’t being handled (which would be with the .htaccess routing setup). It should look something like this for yours, note the RewriteBase value:
[code]]czoxNDg6XCINCk9wdGlvbnMgK0ZvbGxvd1N5bUxpbmtzDQpSZXdyaXRlRW5naW5lIE9uDQpSZXdyaXRlQmFzZSAvZ2FsbGVyeS93ZWJ7WyYqJl19cm9vdC8NClJld3JpdGVSdWxlICFcXC4oanN8aWNvfHR4dHxnaWZ8anBnfHBuZ3xjc3N8aHRjfHBkZnx4bWx8c3dmKSQgaW5kZXgucGh7WyYqJl19cA0KXCI7e1smKiZdfQ==[[/code]
Hi,
I have it up– but no matter what I put for username I get ‘invalid username’ error. Even if I just leave the usernames at the default of yours I get the same error=/
http://empyreanevents.com/gallery/webroot/
What am I doing wrong?
Clay,
I tried setting my own username, ‘bmharris’, and get the error you mentioned on your site. I then set the url to:
http://empyreanevents.com/gallery/webroot/album/5218411233950798513/
This is an actual album in my account, so it should load it, but instead I see the following error from your server:
Warning: simplexml_load_file(http://picasaweb.google.com/data/feed/api/user/bmharris/albumid/5218411233950798513) [function.simplexml-load-file]: failed to open stream: no suitable wrapper could be found in /home/adailyad/public_html/Empyreanevents.com/gallery/app/lib/PicasaImageReader.class.php on line 53
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity “http://picasaweb.google.com/data/feed/api/user/bmharris/albumid/5218411233950798513″ in /home/adailyad/public_html/Empyreanevents.com/gallery/app/lib/PicasaImageReader.class.php on line 53
It looks like its related to the PHP configured on the server you’re running on. I haven’t had time to look too much into those errors, but I think thats the source of the problem. Let me know if you find anything additional out. I think you have the gallery configured and setup just fine, its just something not quite right with PHP on the server.
Just also noticed, you’re getting an error I wasn’t seeing:
URL file-access is disabled in the server configuration
Hi Brad,
Are you using fopen in the script? My host says this would be why it is not working– they have fopen off.. they said for me to use curl instead.
Any ideas?
The script uses simplexml_load_file, which under the scenes uses fopen I beleive. If your host allows curl, that would be a fairly easy substitue. You would want to modify the PicasaImageReader.class.php file, located in app/lib/ directory. There are 2 calls to simplexml_load_file(), one in getAlbums(), the other in getAlbum(). I would add a method such as the following, and call it instead of simplexml_load_file(), passing in the same parameters that are going into simplexml_load_file():
[code]]czozNDI6XCINCiAgICBwcml2YXRlIGZ1bmN0aW9uIGdldFhtbCgkdXJsKSB7DQogICAgICAgICRjdXJsID0gY3VybF9pbml0KCk7DQp7WyYqJl19ICAgICAgICBjdXJsX3NldG9wdCgkY3VybCwgQ1VSTE9QVF9VUkwsICR1cmwpOw0KICAgICAgICBjdXJsX3NldG9wdCgkY3VybCwgQ3tbJiomXX1VUkxPUFRfUkVUVVJOVFJBTlNGRVIsIHRydWUpOw0KICAgICAgICBjdXJsX3NldG9wdCgkY3VybCwgQ1VSTE9QVF9IRUFERVIsIGZhe1smKiZdfWxzZSk7DQogICAgICAgICRzdHIgPSBjdXJsX2V4ZWMoJGN1cmwpOw0KICAgICAgICBjdXJsX2Nsb3NlKCRjdXJsKTsNCiAgICAgICB7WyYqJl19IHJldHVybiBzaW1wbGV4bWxfbG9hZF9zdHJpbmcoJHN0cik7DQogICAgfQ0KXCI7e1smKiZdfQ==[[/code]
I haven't tested the code, but that should get you going. Its basically just substituting using curl instead of simplexml_load_file(). Let me know if you run into any issues, of if that works for you. I'll look at adding the use of curl instead of fopen as a configuration parameter.
OK– I got the gallery working– but clicking on an image results in another furl error:
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: URL file-access is disabled in the server configuration in /home/adailyad/public_html/Empyreanevents.com/gallery/app/controller/Index.controller.php on line 40
OK– I’ve got it working.
function save_image($img){
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $img);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
// Getting binary data
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$image = curl_exec($ch);
curl_close($ch);
// output to browser
header(“Content-type: image/jpeg”);
print $image;
}
Changed line 40 of index.controller.php to this: $image = save_image($requestData['src'].’?imgmax=800′);
Awesome! I’m glad you got it working with your server setup. I’ll definately look at pushing the option of using curl as an alternate to the current setup. Thanks for your persistence Clay.
can’t wait for this to work! I’m getting the ‘invalid username’ error regardless of the user name I enter. i’m not extremely seasoned with php but i can make my way around.
I have added this to PicasaImageReader.class.php
private function getXml($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$str = curl_exec($curl);
curl_close($curl);
return simplexml_load_string($str);
}
and i have substituted:
simplexml_load_file
with:
getXml
I know my shared hosting provider supports curl.
Any advise?
Justin, have you tried echo’ing out the string you get back from calling curl_exec, to make sure you’re getting the xml ok? If you have this up anywhere I can view, that might help me give you a hand a little more.
alrighty, so i’m just getting a blank screen (can’t get an echo to display) now when i run the script, running it on:
http://coolestjustinever.com/g/
I use godaddy hosting so i found quite a few online reference explaining that fopen is disabled, and to use curl it requires a proxy. This is the code i’m using, (included getalbums() call so you can see how i’m using it):
private function getXml($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($curl, CURLOPT_PROXY,”http://proxy.shr.secureserver.net:3128″);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
$str = curl_exec($curl);
curl_close($curl);
return simplexml_load_string($str);
}
public function getAlbums() {
$albums = array();
$feed = @getXml($this->feedUrl . $this->user);
if($feed !== false) {
foreach($feed->entry AS $entry) {
$album = ”;
$album->data = $entry;
$album->gphoto = $entry->children($this->ns['gphoto']);
foreach($entry->children($this->ns['media']) AS $mediaGroup) {
$thumbnail = $mediaGroup->thumbnail->attributes();
$album->media->thumbnail['url'] = (string)$thumbnail->url;
$album->media->thumbnail['height'] = (string)$thumbnail->height;
$album->media->thumbnail['width'] = (string)$thumbnail->width;
}
$albums[] = $album;
}
}else {
$albums = null;
}
return $albums;
}
As a start, I would try throwing in debug alerts right before you call curl_exec() and right after. If you’re still not getting any output, I’d try throwing in a die(‘message here’) statement before, then after, and see if its making it past there. My guess is that its not making it past the curl_exec()
(i apologize ahead of time for my lack of php knowlege)
I have added a debug box in the getXml function.
public function getXml($url) {
echo “alert(\”DEBUG\”)”;
$curl = curl_init();
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($curl, CURLOPT_PROXY,”http://proxy.shr.secureserver.net:3128″);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
$str = curl_exec($curl);
curl_close($curl);
return simplexml_load_string($str);
}
________________________________________________
Its not loading my debug box so i assume the function isn’t being called properly bellow:
public function getAlbums() {
$albums = array();
$feed = @getXml($this->feedUrl . $this->user);
if($feed !== false) {
foreach($feed->entry AS $entry) {
$album = ”;
$album->data = $entry;
$album->gphoto = $entry->children($this->ns['gphoto']);
foreach($entry->children($this->ns['media']) AS $mediaGroup) {
$thumbnail = $mediaGroup->thumbnail->attributes();
$album->media->thumbnail['url'] = (string)$thumbnail->url;
$album->media->thumbnail['height'] = (string)$thumbnail->height;
$album->media->thumbnail['width'] = (string)$thumbnail->width;
}
$albums[] = $album;
}
}else {
$albums = null;
}
return $albums;
}
_______________________________________________
any advise?
once again, just wanted to say thanks for taking the time out of your busy schedule. i think that this framework is amazing and extremely impressive, as i have stated, I truly am so excited to get this working.
Hey Justin,
That echo you are doing won’t cause a javascript “alert” to pop up, as its not wrapped in the needed ‘script’ block. Its most likely just getting dumped into your html if you view source. To make things easier, instead of doing an echo, I would use a die() statement right before the curl exec command, see if it gets there, then, remove it and place it after the curl exec call. Something like this should be sufficient for a die statement:
[code]]czoyMjpcIg0KZGllKFwnaSBnb3QgaGVyZVwnKTsNClwiO3tbJiomXX0=[[/code]
I hope that gives you a little help. Die statements a reminiscent of debugging javascript with alert statements, but sometimes in production of you don't have any debug environment setup, its the quick and dirty way to debug something.
so i used the die statement as follows:
public function getXml($url) {
die(‘i got here’);
$curl = curl_init();
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($curl, CURLOPT_PROXY,”http://proxy.shr.secureserver.net:3128″);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
$str = curl_exec($curl);
curl_close($curl);
return simplexml_load_string($str);
}
public function getAlbums() {
$albums = array();
$feed = @getXml($this->feedUrl . $this->user);
doesn’t call it, so it’s not even initiating the function.
Ahah! It looks like your call to the getXml function is wrong, it should have $this in front of it, as follows:
[code]]czo1NjpcIg0KJGZlZWQgPSAkdGhpcy0+Z2V0WG1sKCR0aGlzLT5mZWVkVXJsIC4gJHRoaXMtPnVzZXIpOw0KXCI7e1smKiZdfQ==[[/code]
GETTING BETTER!
This is the code i have and it deffinitly is what you guessed, not executing $str = curl_exec($curl); when i debug before that the die msg comes up, after that i get the result you see on:
http://coolestjustinever.com/g/
public function getXml($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($curl, CURLOPT_PROXY,”http://proxy.shr.secureserver.net:3128″);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
$str = curl_exec($curl);
die(‘i got here’);
curl_close($curl);
return simplexml_load_string($str);
}
any more ideas (sry for being a pest)?
we’re so close!
to help with the debugging a little, if you could dump out the $str you get back from curl when you die, so its just that string in the source, that would help:
[code]]czoxNDpcIg0KZGllKCRzdHIpOw0KXCI7e1smKiZdfQ==[[/code]
ok, done, (just wondering, when starting the function below, should $url be used?) if you goto the site now, it looks like $str is empty.
public function getXml($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($curl, CURLOPT_PROXY,”http://proxy.shr.secureserver.net:3128″);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
die($str);
$str = curl_exec($curl);
curl_close($curl);
return simplexml_load_string($str);
}
and moving the die (like bellow), doesn’t kill the program
private function getXml($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($curl, CURLOPT_PROXY,”http://proxy.shr.secureserver.net:3128″);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
$str = curl_exec($curl);
die($str);
curl_close($curl);
return simplexml_load_string($str);
}
hey brad,
I got the whole thing working, but when you click on an album i get the fadein-fadeout business but it never displays the album. it goes right back to the album thumbs. the urls are correct I think. is this a php configuration issue?
Nathan,
You might try looking at your adroit.conf.php file, and making sure the WEB_ROOT is set to ‘/gallery/webroot/’ for your setup. You’ll also want to make sure that that is setup in .htaccess file for the RewriteBase. If those don’t work let me know.
This is a great solution for the Picasa photo problem. I came up with a way that parses out the img tags from the rss feed, little less elegant than your solution but it does the job. I’ve got the source of my solution over at http://code.lawpower.net if you’re interested. Kinda wish I saw your site first though.
Also, if all you want to do is share some pictures from a picasa album, I just launched a site for the non-coders out there at http://sharemyalbum.com. Makes it easy to prettify your picasa albums, even your mom can figure it out.
@law: That site is great, you’ve done a really nice job streamlining the customization process and making it easy for people to use, great idea.
Yeah.Great.I want to use it to build a personal gallery with picasa
I’m a photographer looking to customize my picasa web album and link it to my website. I want to cover all the picasa goolge stuff. Is that possible. I’m not a major computer person but I can use photoshop. If there is a way to create a template to cover everything except the pictures I’d love to know. Please Help.
Thanks
In short, it is possible, but involves setting up a full website as this demo shows. You end up with your own website, with the look and feel you want, but the images are provided by Picasa. That’s basically what this example and codebase is for.
This is the closest thing yet to what I need. (first Picasa feed system where you can get more than one album), only your enlarged images are not appearing for me.
I just noticed that the other day. I’m guessing it’s a change in the feed structure that is causing it the time out. I plan on looking at in soon to get that fixed.
Hi,
I run a website with over 300 artists that all have their own galleries. At the moment they are pretty timeconsuming to update, so I was thinking that perhaps Picasa would help me. I do however want to keep them in the same style as the rest of the website. I guess you have done this. Do you think it would be possible to do without too much programming skill?