View file includes/inc_make_preview.php

File size: 3.1Kb
<?php

if (!defined('SECURED'))
{
	die("Unknown Error!");
}

function make_preview($filesource,$filedestination) 
{
global $extensions;
$q = 70; //качество thumbnail изображения(от 0 до 100)

$ext = pathinfo($filesource,PATHINFO_EXTENSION);
if(in_array($ext,$extensions['pics']))
	{
	$w=100;
	$str = null; //watermark строка(в нижнем правом углу thumbnail'a)
	$size = 1; // размер шрифта watermark строки
	if($ext=="png") 
		{
		$createfunc='imagepng'; 
		$funci="imagecreatefrompng";
		}
	elseif($ext=="gif") 
		{
		$createfunc='imagegif'; 
		$funci="imagecreatefromgif";
		}
	else 
		{
		$createfunc='imagejpeg'; 
		$funci="imagecreatefromjpeg";
		}

	$im1 = $funci($filesource);
	$w_src = imagesx($im1); 
	$h_src = imagesy($im1);
	if ($w_src > $w) 
		{
		$ratio = $w_src/$w; 
		$w_dest = round($w_src/$ratio); 
		$h_dest = round($h_src/$ratio); 
		$dest=imagecreatetruecolor($w_dest,$h_dest); 
		imagecopyresampled($dest, $im1, 0,0,0,0,$w_dest,$h_dest, imagesx($im1), imagesy($im1)); //resampled сглаживает картинку
		}
	elseif($w_src <= $w) 
		{
		$dest=imagecreatetruecolor($w_src,$h_src);  
		imagecopyresampled($dest, $im1, 0,0,0,0,$w_src,$h_src, $w_src, $h_src);
		}
	// определяем координаты вывода текста 
	$x_text = $w_dest-imagefontwidth($size)*strlen($str)-3; 
	$y_text = $h_dest-imagefontheight($size)-3; 

	// определяем каким цветом на каком фоне выводить текст 
	$white = imagecolorallocate($dest, 255, 255, 255); 
	$black = imagecolorallocate($dest, 0, 0, 0); 
	$gray = imagecolorallocate($dest, 127, 127, 127); 
	if (imagecolorat($dest,$x_text,$y_text)>$gray) $color = $black; 
	if (imagecolorat($dest,$x_text,$y_text)<$gray) $color = $white; 

	// выводим текст 
	imagestring($dest, $size, $x_text-1, $y_text-1, $str,$white-$color); 
	imagestring($dest, $size, $x_text+1, $y_text+1, $str,$white-$color); 
	imagestring($dest, $size, $x_text+1, $y_text-1, $str,$white-$color); 
	imagestring($dest, $size, $x_text-1, $y_text+1, $str,$white-$color); 

	imagestring($dest, $size, $x_text-1, $y_text,   $str,$white-$color); 
	imagestring($dest, $size, $x_text+1, $y_text,   $str,$white-$color); 
	imagestring($dest, $size, $x_text,   $y_text-1, $str,$white-$color); 
	imagestring($dest, $size, $x_text,   $y_text+1, $str,$white-$color); 
	imagestring($dest, $size, $x_text,   $y_text,   $str,$color); 
	
	$fname = str_replace(".$ext", null, basename($filesource));
	$prev_img = $filedestination.'/'.$fname.'_small'.rand(100,99999).'.'.$ext;
	$createfunc($dest,$prev_img,$q);
	@chmod ($prev_img, 0777);
	return $prev_img;
	}
elseif(in_array($ext,$extensions['video']))
	{
	if(class_exists('ffmpeg_movie'))
		{
		$mov = new ffmpeg_movie($filesource); 
		$ff_frame = $mov->getFrame(1); 
		$gd_image = $ff_frame->toGDImage(); 
		$fname = str_replace(".$ext", null, basename($filesource));
		$prev_img = $filedestination.'/'.$fname.'_small'.rand(100,99999).'.jpg';
		imagejpeg($gd_image, $prev_img, $q);
		@chmod ($prev_img, 0777);
		return $prev_img;
		}
	else return false;
	}
return false;	
}
?>