Location: PHPKode > scripts > picKLE > PNpicKLE-1.0beta/functions.php
<?php
  //
  // Someone posted this function on phpbuilder.net but can't remember who
  //

function array_qsort2(&$array, $column=0, $order=SORT_ASC, $first=0, $last= -2) 
{ 
  // $array  - the array to be sorted 
  // $column - index (column) on which to sort 
  //          can be a string if using an associative array 
  // $order  - SORT_ASC (default) for ascending or SORT_DESC for descending 
  // $first  - start index (row) for partial array sort 
  // $last  - stop  index (row) for partial array sort 

  if($last == -2) $last = count($array) - 1; 
  if($last > $first) { 
   $alpha = $first; 
   $omega = $last; 
   $guess = $array[$alpha][$column]; 
   while($omega >= $alpha) { 
     if($order == SORT_ASC) { 
       while($array[$alpha][$column] < $guess) $alpha++; 
       while($array[$omega][$column] > $guess) $omega--; 
     } else { 
       while($array[$alpha][$column] > $guess) $alpha++; 
       while($array[$omega][$column] < $guess) $omega--; 
     } 
     if($alpha > $omega) break; 
     $temporary = $array[$alpha]; 
     $array[$alpha++] = $array[$omega]; 
     $array[$omega--] = $temporary; 
   } 
   array_qsort2 ($array, $column, $order, $first, $omega); 
   array_qsort2 ($array, $column, $order, $alpha, $last); 
  } 
}

function thumbnail($image_path,$thumb_path,$image_name,$orig_x,$orig_y,$tmax_x,$tmax_y) { 
	//% to scale by in the x direction 
	$x_scale = $tmax_x/$orig_x; 
	//% to scale by in the y direction 
	$y_scale = $tmax_y/$orig_y; 
	//use the scale that is smaller as using the larger scale will cause 
	//one of the dimensions to be greater then our spcified maximum 
	if($x_scale < $y_scale) { 
		$new_y = round($orig_y * $x_scale,0); 
		$new_x = $tmax_x; 
	} else { 
		$new_x = round($orig_x * $y_scale,0); 
		$new_y = $tmax_y; 
	} //end if 
	//return array($new_x,$new_y);
	$make_magick = system("convert -size $new_x"."x"."$new_y -geometry $new_x"."x"."$new_y $image_path/$image_name $thumb_path/$image_name");
}
function resize($image_path,$image_name,$orig_x,$orig_y,$max_x,$max_y) { 
	//% to scale by in the x direction 
	$x_scale = $max_x/$orig_x; 
	//% to scale by in the y direction 
	$y_scale = $max_y/$orig_y; 
	//use the scale that is smaller as using the larger scale will cause 
	//one of the dimensions to be greater then our spcified maximum 
	if($x_scale < $y_scale) { 
		$new_y = round($orig_y * $x_scale,0); 
		$new_x = $max_x; 
	} else { 
		$new_x = round($orig_x * $y_scale,0); 
		$new_y = $max_y; 
	} //end if 
	//return array($new_x,$new_y);
	if($orig_x < $max_x and $orig_y < $max_y){}else{
		$make_magick = system("convert -size $new_x"."x"."$new_y -geometry $new_x"."x"."$new_y $image_path/$image_name $image_path/$image_name");
	}
}
?>
Return current item: picKLE