Skip to main content

Picasa Photos in Blogger

I've been working on ways to get photos from Picasa into my Blogger hosted website. The normal slideshow doesn't work for me as it takes the user away to the Picasaweb pages.

Also when you take photos in the volumes I do, adding them one by one also doesn't work.

I had a look at the Picasa API options from Google, and was able with this simple PHP script to at least generate HTML code for each photo in a Picasa album. Host this somewhere or local using WAMP server.

Find the user ID and album ID, feed it in and run the script. When the output looks like you want it, view source and copy from <table> to </table> into your Blogger post.

The 'style="float: right; margin-bottom: 1em; margin-left: 1em;"' is the part that makes the click of a thumbnail load as a pop-up and not in a new window.

I want to work out a way to add Facebook Like and Google+ on a per photo level so I will probably update this script.

<!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" xml:lang="en" lang="en">
<head>
    <title>PicasaWeb Albums</title>
<?php
    // Check if action is set
    if(isset($_POST["action"]))
    {
        switch($_POST["action"])
        {
            case "user_submit" :
                // Submission from the number submit form
                header("Location: ".$_SERVER["PHP_SELF"]."?user=".$_POST["user"]."&album=".$_POST["album"]);
                die();
            default :
                die("Unknown action : ".$_POST["action"]);
            break;
    }
}
?>
</head>

<body>

<?php
                    global $_GET;
                    $user=$_GET[user];
                    $album=$_GET[album];
                    $user=preg_replace("/[^A-Za-z0-9.]/","",$user);
                    $album=preg_replace("/[^A-Za-z0-9.]/","",$album);
        
?>

    <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
        <input type="hidden" name="action" value="user_submit" />
        Please enter a PicasaWEB user ID : <input type="text" name="user" value="<?php echo $user; ?>"/><br>
        Please enter a PicasaWEB album ID : <input type="text" name="album" value="<?php echo $album; ?>"/><br>
        <input type="submit" value="Submit" />
    </form>

<?php

    // set feed URL
    $feedURL = 'https://picasaweb.google.com/data/feed/base/user/'. $user .'/albumid/'. $album;

    // read feed into SimpleXML object
    $sxml = simplexml_load_file($feedURL);
    
    echo "<table border=0><tr>";
    $cellnr = 0;
    
    // iterate over entries in feed
    foreach ($sxml->entry as $entry) {

        // get nodes in media: namespace for media information
        $media = $entry->children('http://search.yahoo.com/mrss/');
    
        // get thumbnail
        $attrs = $media->group->thumbnail[1]->attributes();
        $thumbnail = $attrs['url'];
        
        // get image
        $attrs = $media->group->content->attributes();
        $image = $attrs['url'];
        
        if ($cellnr == 4) { 
            echo '</tr><tr>'; 
            $cellnr = 1;
        } else {
            $cellnr = $cellnr + 1;
            }
        
        echo '<td valign="middle">';
        echo '<center><a href="' . $image . '" style="float: right; margin-bottom: 1em; margin-left: 1em;">';
        echo '<img src="' . $thumbnail . '" /></a><br>';
        echo '</center>';
        echo '</td>';
        
    }

        echo "</tr></table>
        
        </body>";

?>

The source code part of this post was generated at http://formatmysourcecode.blogspot.com/

Comments

Popular posts from this blog

Double Bunk in Caravan

With our family expanding, we faced a challenge of adding another berth in our caravan, but I did not want to make it permanent. A couple of options are available, of which one is simply to add a bunk to the single berth. We however did not want to cause any permanent markings on the interior of the caravan .

Netdata + SNMP + Mikrotik

Always wanted to see my Internet line usage as a gauge without having to log into the router. So today I configured SNMP in Netdata to collect from my Mikrotik router. /etc/netdata/node.d/snmp.conf: { "enable_autodetect": false, "update_every": 5, "max_request_size": 100, "servers": [ { "hostname": "10.1.1.1", "community": "public", "update_every": 5, "max_request_size": 50, "options": { "timeout": 20 }, "charts": { "mikrotik1.cpu": { "title": "CPU ", "units": "percentage", "type": "line", "family": "cpu", "dimensions": { "used&

CasparCG Simple Playlist

It is possible to build a simple playlist as a rundown in the CasparCG client. It will very simply play each item after each other that are on the same layer. In this very simple post I show how to build such a playlist including the very important step of activating the OSC. The Open Sound Control (OSC) implementation is how the client knows what the server is doing and then being able to send new command back to the server when a piece of media has ended to trigger playback of the next piece. For more details on the OCS, please see  http://casparcg.com/wiki/CasparCG_OSC_Protocol