<?php
/* BEGIN SECTION:   Thumbnail common functions
 *
 *        Thumbnail 
 */

// getThumbnailURL($pic): generate proper thumbnail file path
// $pic: picture
function getThumbnailURL($pic){
  global $pic_extentions,$data_directory;
  $base = preg_replace($pic_extentions,'',$pic);
  $thumb = $data_directory.'/thumbs/'.$base . ".jpg";
  if (!file_exists($thumb)){
    $thumb = $data_directory.'/thumbs/'.$pic . ".jpg";
  }
  return $thumb;
}

// validThumbnailExists(): determins if the picture already has an existing thumbnail
// $pic: picture path relative to album_directory
function validThumbnailExists($pic){
	global $album_directory, $gd_available;
	$thumb_time = 0;
	$tn_file_name = getThumbnailFile($pic);
	@$thumb_time = filemtime($tn_file_name);
	@$pic_time = filemtime("$album_directory/$pic");
	// compare mod dates of picture and thumbnail
	// use out-of-date thumbnails if GD is not available

	if ($thumb_time!==FALSE && (!$gd_available || $pic_time<=$thumb_time)){
		$result = true;
	} else {
		$result = false;
	}
	return $result;
}

// getThumbnailFile($pic): generate proper thumbnail file path
// $pic: picture
function getThumbnailFile($pic){
  return getThumbnailURL($pic);
  global $data_directory;
  return "$data_directory/thumbs/$pic.jpg";
}

/* END SECTION:   Thumbnail common functions
 */
?>