
/*
    Сниппет создания миниатюр
    Кеш в папке /assets/cache/images/*.*
    @img - имага
    @opt - параметр w_110,h_92,zc_1
	@folder - доп папки если необходимо
*/
	//return $img;

    $replace  = Array("," => "&", "_" => "=");
    $options  = strtr($opt, $replace);
    $filename = md5($img.$options); 
    $cache    = isset($cache) ? $cache : false;
    if ($img[0] != "/") $img = "/".$img;
	$nophoto  = isset($nophoto) ? $nophoto : "content/no_photo.jpg";
	if (!file_exists($_SERVER['DOCUMENT_ROOT'].$img) || is_dir($_SERVER['DOCUMENT_ROOT'].$img)) $img = "/images/".$nophoto;
    $options .= "&f=jpg";
    require_once $_SERVER['DOCUMENT_ROOT']."/assets/snippets/phpthumb/phpthumb.class.php";
    $phpThumb = new phpthumb();
    $phpThumb->setSourceFilename($img); 
    $options  = explode("&", $options);
    foreach ($options as $value) {
       $thumb = explode("=", $value);
       $phpThumb->setParameter($thumb[0], $thumb[1]);
    }

	if ($folder != "") {
		$tree = explode("/", $folder);
		$path = $_SERVER['DOCUMENT_ROOT']."/assets/cache/images";
		if (is_array($tree))
		foreach($tree as $dir) {
			$mk = $path. "/" .$dir;
			if (!file_exists($mk)) {
				//echo $mk."<br>";
				mkdir($mk);
				chmod($mk, 0777);
			}
			$path .= "/" . $dir;
		}
		$folder .= "/";
	}

    $outputFilename = $_SERVER['DOCUMENT_ROOT']."/assets/cache/images/".$folder.$filename.".jpg";
    if ($cache && file_exists($outputFilename)) unlink($outputFilename);
    if (!file_exists($outputFilename))
       if ($phpThumb->GenerateThumbnail())
           $phpThumb->RenderToFile($outputFilename);
    $res = explode("/assets", $outputFilename); 
    $res = "/assets".$res[1];
    return $res;
