<?PHP

/*
	*set_paths(); should be called before attempting to use set_tinfo(); or set_sinfo();
	*thumb_exist() will set $t_name because you should always check if the thumb dose exist
	before using it's name
	*unset_t_info is called when checking for thumbs if there is a picture with the given
	thumb name but it's not the rite thumb nail size
	*unset_t_info was only written for consistancy and portability
	*var $descript was included for future use. later I'll probably write a function to find
	the description of the current picture.
*/
class image
{
	var $basepath;	//path of the gallery directory "getcwd();"
	var $descript;	//description of current image (implimitation later)
	
	var $t_name;	//name of the thumb nail
	var $s_name;	//name of the source file
	
	var $t_path;	//path to thumbs on top of basepath
	var $s_path;	//path to sources on top of basepath
	
	var $t_type;	//type of image the thumb is, makes class more portable
	var $s_type;	//type of image the source, makes class more portable
	
	var $t_width;	//width of thumb
	var $s_width;	//width of source
	
	var $t_height;	//height of thumb
	var $s_height;	//height of source
	
	var $t_filesize;	//size of thumb file
	var $s_filesize;	//size of source file
	
	var $t_dims;	//string for withd and height of thumb
	var $s_dims;	//string for withd and height of source
	
	function set_paths($base, $thumb, $source) {
		$this->basepath	= $base;
		$this->t_path	= $thumb;
		$this->s_path	= $source;
	}
	
	function thumb_exist ($filename, $maxsize) {
		$exist	= FALSE;
		$this->t_name = $filename;
		$current = $this->basepath.$this->t_path.$this->t_name;

		if (file_exists($current)) {
			$this->set_t_info ($filename);
			if ($this->t_width == $maxsize || $this->t_height == $maxsize) {
				if ($this->t_width <= $maxsize && $this->t_height <= $maxsize)
					$exist = TRUE;
				else
					$this->unset_t_info();
			}
		}

		return $exist;
	}
	
	function calc_t_dims ($maxsize) {
		if ($this->s_width > $this->s_height) {
			$this->t_width = $maxsize;
			$this->t_height = ceil(($maxsize / $this->s_width) * $this->s_height);
		}
		else {
			$this->t_height = $maxsize;
			$this->t_width = ceil(($maxsize / $this->s_height) * $this->s_width);
		}
	}
	
	function set_t_info($filename) {
		$current		= $this->basepath.$this->t_path.$filename;
		$info			= getimagesize ($current);
		
		$this->t_name	= $filename;
		$this->t_width	= $info[0];
		$this->t_height	= $info[1];
		$this->t_type	= $info[2];
		$this->t_dims	= strtoupper($info[3]);
		$this->t_filesize	= filesize($current);
		
		return $info? TRUE:FALSE;
	}
	
	function set_s_info($filename) {
		$current		= $this->basepath.$this->s_path.$filename;
		$info			= getimagesize ($current);
		
		$this->s_name	= $filename;
		$this->s_width	= $info[0];
		$this->s_height	= $info[1];
		$this->s_type	= $info[2];
		$this->s_dims	= strtoupper($info[3]);
		$this->s_filesize	= filesize($current);
		
		return $info? TRUE:FALSE;
	}	

	function unset_t_info() {
		unset($this->t_width, $this->t_height, $this->t_type, $this->t_dims, $this->t_filesize);
	}

	function unset_s_info() {
		unset($this->s_width, $this->s_height, $this->s_type, $this->s_dims, $this->s_filesize);
	}	

}	/* end include check */
?>
