< Browse > Home / General, HowTo, PHP, Web Development / Blog article: Show pictures from Picasa albums in your custom we...

| RSS

Show pictures from Picasa albums in your custom website using Zend Framework

June 13th, 2010 | 2 Comments | Posted in General, HowTo, PHP, Web Development

Zend Framework and Zend Gdata API provide a simple and effective solution to display pictures and galleries from your picasa account in your own custom website. Lets take one of the public galleries in picasa show it in a custom php page in this website.

Zend Framework
Before we start. In order to use Zend Gdata API, you need to have Zend framework (1.6 or higher) installed, If you have the full framework package installed , you won’t need to worry about anything, you can go ahead and start calling the APIs directly, In case if you don’t have the full framework package installed, you will have to download and configure Google Data Client Library. Details of setup and configuration are listed in the following link

http://code.google.com/apis/gdata/articles/php_client_lib.html#gdata-installation

CODE :)
The following url refers to a public picasa gallery

http://picasaweb.google.com/shasankar/SampleGallery#

The URL has two important pointers, the picasa user id the one that follows the picasaweb.google.com domain, its usually the picasa user name, in some cases it can also be a long alphanumeric string, this is the user id, the other one is the gallery name, in this case it is ‘SampleGallery’

The following script allows you to load pictured directly into your website


<?php
error_reporting(E_ALL);
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_Photos');

// Album and User
$sUserID = "shasankar";
$sAlbumName = "SampleGallery";

$serviceName = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
$gp = new Zend_Gdata_Photos();
$query = $gp->newAlbumQuery();
$query->setUser($sUserID);
$query->setAlbumName($sAlbumName);
$query->setImgMax("800");
$query->setThumbSize("160");
$albumFeed = $gp->getAlbumFeed($query);
$sPrintThumbs = "";

foreach ($albumFeed as $albumEntry) {
if ($albumEntry->getMediaGroup()->getThumbnail() != null) {
// Load Thumbnail Info
$mediaThumbnailArray = $albumEntry->getMediaGroup()->getThumbnail();
$ThumbnailUrl = $mediaThumbnailArray[0]->getUrl();
$ThumbnailHeight = $mediaThumbnailArray[0]->getHeight();
$ThumbnailWidth = $mediaThumbnailArray[0]->getWidth();
// Load Picture Info
$mediaArray = $albumEntry->getMediaGroup()->getContent();
$ImageUrl = $mediaArray[0]->getUrl();
$sImageTitle = $albumEntry->getMediaGroup()->getDescription()->text;
$url = $albumEntry->getLink('alternate')->href;

$sLinkString = <<<LTEXT
<a href="$ImageUrl" title="$sImageTitle"><img src="$ThumbnailUrl" width="$ThumbnailWidth" height="$ThumbnailHeight" /></a>
LTEXT;
$sPrintThumbs .=$sLinkString ;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Loading pictures from Picasa Gallery</title>
</head>
<body >
<div>
<div>
<h3>SampleGallery (Picasa)</h3>

</div>
<div>
<?php echo $sPrintThumbs; ?>
</div>
</div>
<div class="clear"></div>
</body>
</html>

The Api allows lot of customization options, thumbnail size, final image size, number of results per page, etc, these setting have to passed along with the Album query that is sent to picasa.

Picasa album in Custom Webpage

Related Links

If you want to display private picasa galleries in your website, you can make use of zend authentication api, you can read more about it here

http://www.ibm.com/developerworks/library/x-picasalbum/#c5

Leave a Reply 5665 views, 2 so far today |
Follow Discussion

2 Responses to “Show pictures from Picasa albums in your custom website using Zend Framework”

  1. Michael Kerr Says:

    Hi Krishna,

    I’ve been working with the Internet for 15 years and have been programming whenever the need has come up but I’ve found that I’ve had no trouble doing what I needed to do. I’ve always done what was needed to solve a given problem but never have specialized.

    My business has shut down recently and I’m planning on getting my Zend Certification. I was searching for study resources and found your interesting blog. I am sure that you are very busy and you don’t know me but I am wondering if you can give me a specific idea of what level the exams are at.

    Currently I program in PHP and have been able to do everything I’ve ever needed to do. I am new to classes and inheritance though. I’ve worked with MySQL always and use so many different references. I haven’t memorized hundreds of global functions and I really am nervous about the exam. I am in a situation that has left me with very little money so I hate to purchase the exam before I’m ready. Do you think someone who builds applications without using Zend Framework MVC and who doesn’t use objects from classes can get to the required level? I expect I can but I am just very nervous. I’ve integrated some of Zend Framework’s modules into applications and have worked on several projects in PHP

    If you have any thoughts please pass them on.

    Sincerely, and thank you in advance if you have time

  2. Kris Says:

    Hi Mihcael,

    I haven’t had time to check the blog during the last couple of months. I just managed to complete my certification few weeks ago, I have posted my preparations for the exam in this post
    http://www.clickoffline.com/2011/02/zend-certified-framework-engineer-zfce-passed/

    Good Luck!

    - Kris

Leave a Reply