function.php 3.42 KB
<?php
function Redirect($path){
 header('location:' . $path);
}

function translitIt($str) 
{
    $tr = array(
        "À"=>"a","Á"=>"b","Â"=>"v","Ã"=>"g",
        "Ä"=>"d","Å"=>"e","Æ"=>"j","Ç"=>"z","È"=>"i",
        "É"=>"y","Ê"=>"k","Ë"=>"l","Ì"=>"m","Í"=>"n",
        "Î"=>"o","Ï"=>"p","Ð"=>"r","Ñ"=>"s","Ò"=>"t",
        "Ó"=>"u","Ô"=>"f","Õ"=>"h","Ö"=>"ts","×"=>"ch",
        "Ø"=>"sh","Ù"=>"sch","Ú"=>"","Û"=>"yi","Ü"=>"",
        "Ý"=>"e","Þ"=>"yu","ß"=>"ya","à"=>"a","á"=>"b",
        "â"=>"v","ã"=>"g","ä"=>"d","å"=>"e","æ"=>"j",
        "ç"=>"z","è"=>"i","é"=>"y","ê"=>"k","ë"=>"l",
        "ì"=>"m","í"=>"n","î"=>"o","ï"=>"p","ð"=>"r",
        "ñ"=>"s","ò"=>"t","ó"=>"u","ô"=>"f","õ"=>"h",
        "ö"=>"ts","÷"=>"ch","ø"=>"sh","ù"=>"sch","ú"=>"y",
        "û"=>"yi","ü"=>"","ý"=>"e","þ"=>"yu","ÿ"=>"ya","¿"=>"i", "¯"=>"Yi", "º"=>"ie", "ª"=>"Ye", 
        " "=> "_", "."=> "", "/"=> "_","%"=>'vidsotkiv',
    );
    

		return strtolower(strtr($str,$tr));

}

function upload_ImageResize($upload,$option){

	// *** 1) Initialise / load image
	$resizeObj = new resize($upload);

	// *** 2) Resize image (options: exact, portrait, landscape, auto, crop)
	$options = isset($option['crop']) ? 'crop' : 'auto';
	$resizeObj -> resizeImage($option["width"], $option["height"], $options);

	// *** 3) Save image
	$type = substr(strrchr($upload['name'],"."),1);
    $nameFile = mktime() . "_" . rand(1,10000) . "." . $type;
    $save_image = $option["upload_path"] . $nameFile;
	$resizeObj -> saveImage($save_image, 100);


	

return $nameFile;
}

        function upload_ImageResize2($upload,$option){

   $type = substr(strrchr($upload['name'],"."),1);
   $newWidth = $option["width"];
   $newHeight = $option["height"];
   $nameFile = mktime() . "_" . rand(1,10000) . "." . $type;
   $save_image = $option["upload_path"] . $nameFile;
   $img = $upload["tmp_name"];

switch($type){
case "jpg":
   $function_image_create = "ImageCreateFromJpeg";
   $function_image_new = "ImageJpeg";
case "jpeg":
   $function_image_create = "ImageCreateFromJpeg";
   $function_image_new = "ImageJpeg";
break;
case "png":
   $function_image_create = "ImageCreateFromPng";
   $function_image_new = "ImagePNG";
break;
case "gif":
   $function_image_create = "ImageCreateFromGif";
   $function_image_new = "ImageGif";
break;
default:
   $function_image_create = "ImageCreateFromJpeg";
   $function_image_new = "ImageJpeg";
break;
}


   $srcImage = @$function_image_create($img);

   $srcWidth  = ImageSX($srcImage);
   $srcHeight = ImageSY($srcImage);


  if ( ($newWidth < $srcWidth) || ($newHeight < $srcHeight) ) {
   if( $srcWidth < $srcHeight ){
       $destWidth  = $newWidth * $srcWidth/$srcHeight;
       $destHeight = $newHeight;
   }else{
       $destWidth  = $newWidth;
       $destHeight = $newHeight * $srcHeight/$srcWidth;
   }
  }else{ $destWidth = $srcWidth;$destHeight = $srcHeight;}



   $destImage = imagecreatetruecolor($destWidth, $destHeight);

   ImageCopyResampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
           /*
   if(isset($option['str']) && strlen($option['str'])>0){
    $colorGrey=imagecolorallocate($destImage, 192, 192, 192);
    $height_str = $destHeight-7;
    imagettftext($destImage,15,0,7,$height_str,$colorGrey,"{$_SERVER['DOCUMENT_ROOT']}/libs/fonts/ds_zombi.ttf",$option['str']);
   }   */
  @$function_image_new($destImage,$save_image,100);


   ImageDestroy( $srcImage  );
   ImageDestroy( $destImage );

return $nameFile;
}

?>