Home
Jason S. Kivlighn :: Portfolio

Drupal Module :: Photobar :: Documentation

This module enables automatically importing directories as galleries of images. For each gallery, a photobar preview of the gallery is created for display on the main-page. Where this module shines is it's simplicity and automation. Photos need simply to be placed in the required directory on the server, and the photobars will automatically be created and inserted in the correct place in the site. Unlike other photo managing modules, no installation is required nor does it require altering Drupal's database.

It is best suited for use with cron to completely automate the process of creating galleries. Cron will automatically find all photo directories and create a photobar and gallery for them. If a gallery already exists by a given date, new photos will be added to the gallery.

Photobar works with the 'image' and 'image_gallery' modules, available on drupal.org as contributed modules. Photobar uses the 'image' module to create each photo as a node. The creation date of the photo node will be read from exif data if available and otherwise will match the date of the folder. Those nodes are added to an image gallery using the 'image_gallery' module.

The creation date of each photobar node will be the date of the folder name.

Installation

Simply copy photobar.module into drupal's modules/ directory and enable it through administermodules.

It will also require the 'image' and 'image_gallery' modules to be enabled. If these modules are not installed, they can be downloaded from http://drupal.org/project/image. Both modules are provided by the 'image' package and installation of these modules is as simple as placing it in the modules/ directory and enabling it (these modules have no external dependencies).

Usage

Photobars are created per-date. The date is determined by the folder name, which must be in the form YYYY-MM-DD.

Put any number of folders in the specified directory ('files/photos' by default), run cron, and watch your photobars and galleries be created :-) Photobars can manually be added by placing the folder of photos in the appropriate directory and specifying that folder in create contentphotobar.

When deleting a photobar, the image gallery it created, as well as all the photos in that gallery will be deleted.

NOTE: The only method of adding photos is by directly placing the photos on the server. There is no method through Drupal or this module to upload photos.

Theming

To give the photobar the simple look above, you may wish to alter your theme to have photobar nodes only display their content (and not a title, publication date, etc.). To do so, create a file node-photobar.tpl.php and place it into themes/{your theme}/. I would recommend that the file contain only the line:

<div class="content"><?php print $content?></div>

The photobar may be styled using CSS. Here is the CSS, as well as graphics, for the photobar above.

Note: You will have to edit the files tl.gif and bl.gif and make them wider if your photobar is longer than 700 pixels. Here's a 1200px wide version if you need them: tl.gif, bl.gif

.photobar td {
 border-left: 2px solid gray;
}

.photobar .first {
  border-style: none;
}

.photobar {
 width:67%;
 margin:0px auto;
 min-width:20em;
 color:#fff;
 background:#000 url(fade.gif) repeat-x 0px 0px;
}

.photobar .hd .c,
.photobar .ft .c {
 font-size:1px; /* ensure minimum height */
 height:12px;
}

.photobar .ft .c {
 height:12px;
}

.photobar .hd {
 background:transparent url(tl.gif) no-repeat 0px 0px;
}

.photobar .hd .c {
 background:transparent url(tr.gif) no-repeat right 0px;
}

.photobar .bd {
 background:transparent url(ml.gif) repeat-y 0px 0px;
}

.photobar .bd .c {
 background:transparent url(mr.gif) repeat-y right 0px;
}

.photobar .bd .c .s {
 margin:0px 8px 0px 4px;
 padding:1em;
}

.photobar .ft {
 background:transparent url(bl.gif) no-repeat 0px 0px;
}

.photobar .ft .c {
 background:transparent url(br.gif) no-repeat right 0px;
}

The HTML itself may be customized with a little knowledge of PHP. Adding this function to themes/{your theme}/template.php will create a 'photo square':


<?php
function phptemplate_photobar$images$gallery_path ) {
  
$count count($images);
  
$cols ceil(sqrt($count));

  
$content "<table><tr>";
  for ( 
$i 0$i $count$i++ ) {
    if ( 
$i != && $i $cols == ) {
            
$content .= "</tr><tr>;";
    }

    
$content .= '<td><img src="'.$images[$i].'" /></td>';
  }
  
$content .= "</tr></table>";

  
//make the entire table a link to the gallery
  
$content l($content$gallery_path, array(), NULLNULLTRUETRUE);

  return 
$content;
}
?>

Configuration

Configuration is done through administersettingsphotobar

Photo search path:

-Where to look on the server for photos.

Maximum photos to display:

-Number of photos to display in a photobar.

Image label:

-This label must match one of the labels defined in the 'image' module settings. To define the size of photos in the photobar, create a label in settingsimage with the desired size. Specify this new (or already existing label) here.

NOTE: Labels must already exist at the time the photos were added. If you input photos, then create a new label and set it here, photos won't appear for this label. In fact, no photos will appear at all.

Auto-orient:

-Orient photos based on exif info (requires php configured with --enable-exif). This doesn't affect photos already added.

Default user id:

-When nodes are created via cron, photobar will create nodes owned by the user with this id.