Viewing File: /home/cienp/public_html/portal/includes/thumbjpg.php

<?
	function resize_img($imagem, $diretorio, $prefix, $f_wi, $f_he) {
		
		$img = ImageCreateFromJpeg($diretorio.$imagem);

		$wi = ImageSX($img);
		$he = ImageSY($img);

		if (($wi > $f_wi)
		 || ($he > $f_he)) {
			if ($wi > $he) {
				$img_wi = $wi * $f_he / $he;
				$img_he = $f_he;
			} else {
				$img_he = $he * $f_wi / $wi;
				$img_wi = $f_wi;
			}
			if ($img_wi < $f_wi) {
				$img_wi = $f_wi;
				$img_he = $he * $f_wi / $wi;
			}
			if ($img_he < $f_he) {
				$img_wi = $wi * $f_he / $he;
				$img_he = $f_he; 	
			}
		} else {
			$img_wi = $wi;
			$img_he = $he;
		}

	    $img_nova = imagecreatetruecolor($img_wi,$img_he);
	    imagecopyresampled($img_nova, $img, 0, 0, 0, 0, $img_wi, $img_he, $wi, $he);

	    Imagepng($img_nova, $diretorio.$prefix.$imagem);
	    ImageDestroY($img);
		ImageDestroy($img_nova);
		
		if (($img_wi >= $f_wi)
	     && ($img_he >= $f_he)) {
		
			// retira um pedaço da imagem
			$img = ImageCreateFrompng($diretorio.$prefix.$imagem); 
			
			$wi = ImageSX($img);
			$he = ImageSY($img);
			
			$wi_nova = $f_wi;
			$he_nova = $f_he;
			
			$wi_metd = $f_wi/2;
			
			$wi_olds = (int)($wi / 2);
			
			$he_inic = 0;
			if ($wi > $he)
				$wi_inic = $wi_olds - $wi_metd; 
			else
				$wi_inic = 0;
			
			$img_nova = imagecreatetruecolor($wi_nova,$he_nova); 
			imagecopy($img_nova, $img, 0, 0, $wi_inic, $he_inic, $wi_nova, $he_nova); 
			
			Imagepng($img_nova, $diretorio.$prefix.$imagem); 
		    ImageDestroY($img); 
			ImageDestroy($img_nova);
	     }
		
		return 1;
	}
	
	function redi($imagem, $diretorio) {

		$img = ImageCreateFromJpeg($diretorio.$imagem); 
    	
		$wi = ImageSX($img);
		$he = ImageSY($img);
		
		if (($wi > 800)
		 || ($he > 600)) {
			if ($wi > $he) {
				$img_wi = 800;
				$img_he = 800 * $he / $wi;
			} else {
				$img_he = 800;
				$img_wi = $wi * 800 / $he;
			}
		} else {
			$img_wi = $wi;
			$img_he = $he;
		}
									
	    $img_nova = imagecreatetruecolor ($img_wi,$img_he); 
	    imagecopyresampled($img_nova, $img, 0, 0, 0, 0, $img_wi, $img_he, $wi, $he);    
	    
		Imagepng($img_nova, $diretorio.$imagem); 
	    ImageDestroY($img); 
		ImageDestroy($img_nova);
		
		return 1;
	}
	
	
		
?>
Back to Directory File Manager