<?

class Images {

function Images() {
	if (function_exists("imagegif")) {
		$this->canGIF = true;
	}
	if (function_exists("imagejpeg")) {
		$this->canJPG = true;
	}
	if (function_exists("imagepng")) {
		$this->canPNG = true;
	}
}


function getImageType($file) {
	$fp = fopen($file, "r");
	$header = strtoupper(fread($fp, 15));
	fclose($fp);
	if(strstr($header,"PNG")){
		return "png";
	}elseif(strstr($header,"GIF")){
		return "gif";
	}elseif(strstr($header,"JFIF") || strstr($header,"EXIF")){
		return "jpeg";
	} else {
		return false;
	}
}

function isImage($filename) {
	global $fm;
	$ext = strtolower($fm->getExtension($filename));
	if ($ext == "jpg" || $ext == "png" || $ext == "gif" || $ext == "jpeg") {
		return true;
	} else {
		return false;
	}
	
}

function icon($fullpath,$thumb=false,$bigthumb=false, $relativePath) {
	global $fm, $iconfolder, $sys, $str;
	$filename = basename($fullpath);
	$ext = strtolower($fm->getExtension($filename));
	$filetypeinfo = $fm->fileTypeInfo($ext);
	$icon = $filetypeinfo['icon'];
		if ($ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "gif") {
			if ($thumb && extension_loaded("gd") == true) {
			global $sys;
			$imagetype = $this->getImageType($fullpath);
			if ($imagetype) {
			//gd is loaded, file is an image, create thumbnail
			$imageSizes = @getimagesize($fullpath);
					if ($imageSizes[0] < 2 || $imageSizes[1] < 2) {
								if(!$icon) {
									$icon = gluePath($iconfolder,"generic.gif");
								} else {
									$icon = gluePath($iconfolder,$icon);
								}
					} else {
						$icon = "thumbs.php?path=".$str->forURL($relativePath)."&filename=".$str->forURL($filename);
						if ($sys['uid']) {
							$icon .= "&uid=".$sys['uid'];
						}
					}
			} else {
				//$icon = gluePath($iconfolder,"generic.gif");
				$icon = gluePath($iconfolder,$icon);
			}
		} else {
			$icon = gluePath($iconfolder,$icon);
		}
	} else {
		if(!$icon) {
			$icon = gluePath($iconfolder,"generic.gif");
		} else {
			$icon = gluePath($iconfolder,$icon);
		}
	}
	return $icon;
}

function flaggedIcon() {
	global $sys;
$im = imageCreateFromGif($sys['root']."/images/icons/filetypes/big/xls.gif");


$discussion = imageCreateFromGif($sys['root']."/images/flags/group.gif");

imageCopyMerge($im, $discussion,5,10,0,0,16,16,100);


header("content-type: image/png");
imagePng($im);
}



function isViewable($path) {
	if (@getImagesize($path)) {
		return true;
	} else {
		return false;
	}
}

function thumb($src,$maxWidth,$maxHeight, $fixedSize) {
	global $thumb;
	$thumb->thumb($src,$maxWidth,$maxHeight, $fixedSize);
}


}



?>