Grab a thumbnail based on album id?

I have a pretty extensive Google Map with locations of each album and a different pin for each album type. In the info pop-up, I need to display a thumbnail for the album. Previously I wrote a php script which took album_id as a parameter, then looked up random picture from that album, checked if thumbnail was cached, if not it looped back to choose another random picture, and finally choose one that existed in the album image cache dir.

This step (as you can imagine) turned out to be a huge bottle neck and really slowed down the map. I'd like to make use of a built in zenphoto function to do this (which seems quite fast as evidenced by how the rest of the site works).

What I want is:

`$image_path = BUILT_IN_ZENPHOTO_FUNCTION($album_id);`

Can someone suggest a way to do this?

Comments

  • Hmm, maybe a little research would help you on your way.

    Let's see, how do the themes do this? They call `printAlbumMap()`.

    What does this function expect? Well, an allbum as it uses the normal page functions to get the data from the album's image. So I guess you need to setup the environment to look like an album page with the current album selected and call the above function.
  • Thanks for that suggestion, sbillard.

    I am not looking to use a built in google map implementation. In my case, individual images do not have location info. Only albums do. And I really do not need a map for each image.
    What I have is a separate page called Maps where I have full window google map with a location for each album. Some albums reflect certain types of pictures (and thus have a distinct map marker). I've got this part down.

    It's also easy to query the zp_albums page for a title to show into the map information popup.

    However, I'm having a hard time using existing functions like `printCustomAlbumThumbImage` to grab a thumbnail from each album.

    These zenphoto functions do exactly what I want but unfortunately do not take album_id or title as a parameter. Instead they use the current album id (A global variable from what I understand). This would be useful if I did a map within a current album. However my map is independent of any specific album.

    I wrote this function but as you can imagine, it wont finish till it finds an image in the cache dir. Sometimes this step hangs.

    `

    function album_thumb($id,$folder) {

    global $db;

    do {

    $albe=mysql_query("select filename from zp_images WHERE albumid='$id' order by rand() LIMIT 1",$db);

    $ima=mysql_fetch_array($albe);

    $im=$ima['filename'];

    $im=substr($im,0,-4);

    $im=$im."_100_cw85_ch85_thumb.jpg";

    $image="http://site.org/cache/$folder/$im";

    $path_to_file="/home/user/site.org/cache/$folder/$im";

    $exist=file_exists($path_to_file);

    } while($exist==FALSE);

    return $image;

    }

    `

    I've done quite a bit of looking around (don't mean to give you the impression that I haven't) and am still coming up short.

    Thanks again.
  • I suggest you look at the implemetation of that function. Basically where it is using the $_zp_current_album variable you need to substitute the album object of your choice.

    BTW the reason the functions do not use the album title as a parameter is that it is not necessarily unique. The only unique is the album "name". If all you have is the album id, you would have to query the database for that record and use the folder field for instantiating a new album object.
  • Cool thanks!
    I think I'm also there.

    I understand that album title isn't unique but what is album NAME? Is that a field? Is it the location?
  • it is an internal piece of data of the album object. But what you need to know is that to instantiate an album object you must supply its folder path stemming from "albums" presuming you are using a standard install.
  • I made it work!

    Thanks, sbillard!
Sign In or Register to comment.