Grabbing thumbnail for an album?

I am trying to create a custom page where I display a bunch of info on a google map (using the location field). Right here, I'd like to iteratively grab the thumbnail of each gallery in question. Right now, I can do it with my own php code but only if a default thumbnail image is set. (i.e. I just look up the image in the thumb field and add a path to it).

Unfortunately, I have albums with many sub albums and no default thumb set. Zenphoto does a pretty good job of grabbing a random thumbnail from one of the subalbums for each album in the main index page.

I see that there is a function called printAlbumThumbImage(getAnnotatedAlbumTitle())

Can I use it for my one purpose by giving it an album id as an argument? If so, how? Can I for example say "printAlbumThumbImage(5)" to grab a thumbnail where albumid=5 (be it a root album or a subalbum).

thanks!

Comments

  • I am not a developer with ZP but looked into that function quite a lot
    In my mind you would need to develop a custom function in customfunctions.php in your themes folder. (i.e. have some PHP skills) check zpfocus theme for that !

    in there it could work like this:

    see example below

    a) you pass in $thumbalbum ;
    b) backup real $_zp_current_album
    c) set new album depending on your parameter
    d) revert to real current album at the end;

    `
    function printCustomAlbumThumbImage($thumbalbum=NULL,$alt, $class=NULL, $id=NULL) {
    global $_zp_gallery, $_zp_current_album, $_zp_themeroot;

    $orig_location = $_zp_current_album ;
    if ($thumbalbum) $_zp_current_album = new Album($_zp_gallery, $thumbalbum);

    if (!$_zp_current_album->getShow()) {
    $class .= " not_visible";
    } else {
    $pwd = $_zp_current_album->getPassword();
    if (zp_loggedin() && !empty($pwd)) {
    $class .= " password_protected";
    }
    }
    $class = trim($class);
    if (!getOption('use_lock_image') || checkAlbumPassword($_zp_current_album->name, $hint)) {
    $html = '' . html_encode($alt) . '';
    $html = zp_apply_filter('standard_album_thumb_html', $html);
    echo $html;
    } else {
    if (getOption('thumb_crop')) {
    $s = getOption('thumb_size');
    $w = getOption('thumb_crop_width');
    $h = getOption('thumb_crop_height');
    if ($w > $h) {
    $h = round($h * $s/$w);
    $w = $s;
    } else {
    $w = round($w * $s/$w);
    $h = $s;
    }
    $size = 'width="'.$w.'" height="'.$h.'"';
    } else {
    $size = '';
    }
    echo getPasswordProtectImage($size);
    }

    $_zp_current_album = $orig_location ;

    }
    `
  • acrylian Administrator, Developer
    Much easier as Zenphoto features an object model framework for this kind of custom tasks.
    The unique value for gallery items of Zenphoto never the ID, but the NAME. In case of albums this is the folder name (for subalbums that is `toplevel/sublevel/...`). Using that you can setup an album object for every album you want, independed from being "current".

    So setup an album object:
    1. `$albumobj = new Album($_zp_gallery,"");`
    2. `$albumthumb = $albumobj->getAlbumThumbImage();`
      http://www.zenphoto.org/documentation/classes/Album.html#methodgetAlbumThumb
    I suggest to look at the classes.

    Btw. since 1.2.8 any file named `functions.php` within a theme is loaded automatically as "customfunctions" (like Wordpress does).
Sign In or Register to comment.