All pastes #410499 Raw Edit

Someone

public text v1 · immutable
#410499 ·published 2007-03-26 13:16 UTC
rendered paste body
//------------------------------------+
// Create Thumbnail
//------------------------------------+
include ('logger.php');
log_str("Creating thumbs for files:");
foreach ($filelist4 as $item)
{
$tmp_filename = $item['name'];
log_str("$tmp_filename");
	switch ($item['ext']) {
		case 'jpg': case 'png': case 'gif': case 'bmp': 
			list($oX, $oY, $rubbish1, $rubbish2) = getimagesize($item['tmp_name']);
			
			$item['width'] = $oX;
			$item['height'] = $oY;
			$max = $INFO['thumb_dimension'];
			log_str("X - $oX;//Y - $oY//$max");
			// Determine New X and Y.
			if ($oX <= $max && $oY <= $max)	{	// Smaller than thumbnail limit? use original
				$nX = $oX;
				$nY = $oY;
			}
			elseif ($oX > $max && $oY <= $max)		// X is too large but not Y
			{
				$nX = $max;
				$ratio  = $oX/$nX;
				$nY = (int) $oY/$ratio;
			}
			elseif ($oX <= $max && $oY > $max)		// Y is too large but not Y
			{
				$nY = $max;
				$ratio = $oY/$nY;
				$nX = (int) $oX/$ratio;	
			}
			elseif ($oX >= $oY)	
			{
				$nX = $max;
				$ratio  = $oX/$nX;
				$nY = (int) $oY/$ratio;
			}
			else
			{
				$nY = $max;
				$ratio = $oY/$nY;
				$nX = (int) $oX/$ratio;	
			}
			if ($item['ext'] == 'gif') 
			{
				//echo "TEST TEST TEST GIF";
			}	
			log_str("{$path_to_convert}convert -format jpg -resize $nX"."x"."$nY -quality 75 $item[tmp_name] $item[tmp_name].thumb.jpg");
		$ret = exec("{$path_to_convert}convert -format jpg -resize $nX"."x"."$nY  -quality 75 $item[tmp_name] $item[tmp_name].thumb.jpg");
			if (!$ret) {	// Success
			log_str(" Creation successfull.$ret");
				$item['thumb'] = 1;
			}
			else {
				$item['thumb'] = 0;
				log_str("Error creating.$ret");
				@unlink("$item[tmp_name].thumb.jpg");
			}
		break;
		default:
			$item['thumb'] = 0;
		break;
	}
	$filelist6[] = $item;
}